Are there stackless or heapless implementation of C++?

Others have already given good answers about the heap, so I’ll leave that alone.

Some implementations (e.g., on IBM mainframes) don’t use a stack as most people would think of it, for the simple reason that the hardware doesn’t support it. Instead, when you call a function, an activation record (i.e., space for the locals, arguments, and return address) is allocated from (their version of) the heap. These activation records are built into a linked list.

From a purely abstract viewpoint, this is certainly a stack — it supports last-in, first-out semantics, just like any other stack. You do have to look at it pretty abstractly to call it a stack though. If you showed people a diagram of the memory blocks linked together, I think it’s safe to guess most programmers would describe it as a linked list. If you pushed them, I think most would judge it something like “yeah, you can use it in a stack-like manner, but it’s still a linked list.”

Leave a Comment