I am trying to figure out how C and C++ store large objects on the stack. Usually, the stack is the size of an integer, so I don't understand how larger objects are stored there. Do they simply take up multiple stack "slots"?
...
UPDATE So totally pulled a tool moment. I really meant by reference versus Out/Ref. Anything that says 'ref' I really meant by reference as in
SomeMethod(Object someObject)
Versus
SomeMethod(out someObject)
Sorry. Just don't want to change the code so the answers already make sense.
Far as I understand, unlike ref where it "cop...
Ignoring programming style and design, is it "safe" to call delete on a variable allocated on the stack?
i.e.
int nAmount;
delete &nAmount;
or
class sample
{
public:
sample();
~sample() { delete &nAmount;}
int nAmount;
}
...
Hi,
For a programming class I am creating a blackjack program for the first homework assignment. The professor has given us a sample Card class, which includes the method to add them to a deck. For her deck, she uses an ArrayList, which you can easily Knuth Shuffle with the Collections.shuffle() method.
That method does not work for St...
Is there a way to use the new keyword to allocate on the stack (ala alloca) instead of heap (malloc) ?
I know I could hack up my own but I'd rather not
...
Here is an example that a forum poster gave, I can't tell if this tail optimized. Also, could someone give a laymans description of how a tail optimized version would trump the normal version.
(defun mylength (s)
(labels ((mylength-inner (s x)
(if (car s) (mylength-inner (cdr s) (+ x 1)) x)))
(mylength-inner s ...
From a SO answer about Heap and Stack, it raised me a question: Why it is important to know where the variables are allocated?
At another answer someone pointed that the stack is faster. Is this the only implication? Could someone give a code example where a simple allocation location change could solve a problem (eg. performance)?
Not...
I have the following code:
public class Test
{
public static void Main()
{
List<Person> list = new List<Person>();
Person person = new Person() { Name="Chris" };
list.Add(person);
person = new Person(){ Name="Wilson the cat" };
list.Add(person);
Console.WriteLine(list[0].Name);
Console.WriteL...
Is it possible to create a FIFO 'stack' in C without using 2 stacks?
Thanks!
(Sorry to those who answered the previous one. I was thinking LIFO and meaning FIFO.)
...
I'm using Visual C# to program an RPN calculator using Stack. Problem is I don't know how to do this. I'm using System.Collections.Generic, but
Stack s = new Stack();
generates the error "Using the generic type 'System.Collections.Generic.Stack' requires '1' type arguments"
I'm pretty clueless here. Thanks for the help.
...
I'm using Windbg (with the sos extention) and trying to debug a crashed application. I was able to dump the IL of the call that threw the exception and by examining the code, it seems like I could obtain the information that I need if I could dump the contents of the evaluation stack. Is it possible to do what with WinDbg & sos ?
Here...
I'm reading The C Programming Language and learned how to make a reverse Polish calculator using a stack. Here is one of the exercises that follow it:
Exercise 4-4. Add the commands to print the top elements of the stack without popping, to duplicate it, and to swap the top
two elements. Add a command to clear the stack.
What do ...
Does the stack in the C++ STL expose any iterators of the underlying container or should I use that container directly?
...
Suppose we have these local variables:
int a = 0;
int b = 1;
int c = 2;
int d = 3;
As far as I know, these will be allocated on the system stack, like this:
| |
| 3 | d
| 2 | c
| 1 | b
|_0_| a
Does this mean that in order to get the value of a, the values of d, c and b must first be popped out of the stack? If so, where do these ...
I'm reading through Jon Skeet's book reviews and he is going over the numerous inaccuracies of Head First C#.
One of them caught my eye:
[Under Errors Section] Claiming that structs always live on the stack.
In what situations would structs not live on the stack? This goes contrary to what I thought I knew about structs.
...
Is it possible to programmatically construct a stack (one or more stack frames) in CPython and start execution at an arbitrary code point? Imagine the following scenario:
You have a workflow engine where workflows can be scripted in Python with some constructs (e.g. branching, waiting/joining) that are calls to the workflow engine.
A ...
I'm currently trying to understand how the stack works, so I've decided teach myself some assembly language, I'm using this book:
http://savannah.nongnu.org/projects/pgubook/
I'm using Gas and doing my development on Linux Mint.
I'm a bit confused by something:
As far as I was aware a stack is simply a data structure. So I assumed i...
Hi, how do I check the value of the top of the stack in Lua?
I have the following C++ code:
if (luaL_loadfile(L, filename) == NULL) {
return 0;// error..
}
lua_pcall(L,0,0,0); // execute the current script..
lua_getglobal(L,"variable");
if (!lua_isstring(L,-1)){ // fails this check..
lua_pop(L,1);
retu...
The following code is generating a stack overflow error for me
int main(int argc, char* argv[])
{
int sieve[2000000];
return 0;
}
How do I get around this? I am using Turbo C++ but would like to keep my code in C
EDIT:
Thanks for the advice. The code above was only for example, I actually declare the array in a function and...
My logging code uses the return value of backtrace() to determine the current stack depth (for pretty printing purposes), but I can see from profiling that this is a pretty expensive call.
I don't suppose there's a cheaper way of doing this? Note that I don't care about the frame addresses, just how many of them there are.
edit: These...