Questions tagged [stack]
A LIFO (Last In, First Out) data structure.
79 questions
3votes
4answers
2kviews
Iterating through stacks and queues?
Are stacks and queues allowed to be iterated over, conceptually? It “feels wrong” for some reason but I can't come up with a reason why it would be bad to see through the whole thing that's stacked/...
2votes
4answers
824views
Could a language allow for persistent allocations without heap?
Is it possible in theory to have a programming language that allows for object lifetimes that exist beyond the current scope but without using heap? As a little background, in embedded development it ...
5votes
4answers
370views
Use of globals in stack-based virtual machine implementation
I'm implementing a stack-based virtual machine in C. The following variables are used by pretty much every function: memory array various pointers to memory offsets program counter stack stack ...
0votes
1answer
168views
Which scope should markers for a Stack Allocator fall under?
For reference, I am reading from "Game Engine Architecture 2nd Edition" by Jason Gregory. Although I understand the theory behind Stack Allocators, I am having trouble implementing it fully. ...
-3votes
4answers
2kviews
C# Why should i limit myself to List or Stack ? ( instead of having both)
List is implemented in C# exactly as Stack, see: https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.stack-1.push?view=netframework-4.8#remarks https://docs.microsoft.com/en-us/...
24votes
3answers
4kviews
Are the Stack and Heap hardware, OS, or language-specific concepts?
In languages such as C or Java we have the concepts of the Stack and the Heap. Are these abstractions the particular language runtime/compiler creates over the plain-old RAM? Or are these concepts ...
0votes
3answers
268views
Resolving function calls as function arguments using a stack
After doing a bit of reading, I have a vague understanding of the use of a stack in calling functions when one function calls another, where the arguments are placed on the stack for the called ...
0votes
4answers
8kviews
Is it a good idea to use strings in a struct as values to static properties?
I'm in a discussion with a co-worker concerning the use of structs. I have a couple of structs that contain several static properties that are used throughout our website. The value of those ...
1vote
2answers
2kviews
Should I always allocate QObject and derived classes to the heap?
I was in #Qt irc channel, and I showed a small snippet of my code in a style that I heavily rely upon. It looks like this: /* Get Reply from Server */ QPointer<QNetworkReply> reply; { ...
0votes
1answer
3kviews
Registers and Stacks in NASM
So, I am more or less voluntarily learning NASM, and I have problems finding sources that really explain it. Unlike with Java or C# I can't just use google as well, since Assembly just isn't used by ...
0votes
2answers
223views
How to Implement a `function` with `return` Without Using the `function` keyword
Along the lines of How to Simulate Control-Flow without using Control-Flow Primitives, I am wondering how to simulate return from a function. Given an example setup like this: console.log(a(10)) ...
-3votes
2answers
11kviews
Why we use top== -1 for implementation of stack using simple array?
I am a newbie at data structures. I have read an implementation of a stack using a simple array. The algorithm for this implementation is presented below. Stack implementation in terms of an array ...
4votes
1answer
938views
C++ Are members of a class pointer automatically on heap?
Let's say we have a struct Vector2i { int x = 0, int y = 0 }; And create a Pointer to it via Vector2i* pointer = new Vector2i; Where would int x and int y be stored? Heap or stack? Are all members ...
2votes
3answers
2kviews
How do Stack Machine store global vars?
How exactly do stack machines (both real and virtual stack machines) store global variables? I know that C(++) just compile it to the .data segment of a program's memory segmentation. Then there's ...
2votes
2answers
4kviews
Does Java copy method parameters to the stack frame of the called method?
This is part of the answer about stack and heap in Java: So, why have the stack or the heap at all? For things that leave scope, the stack can be expensive. Consider the code: void foo(String arg)...