Re: Stack is slow than heap?
On 11/7/2011 11:27 AM, Nephi Immortal wrote:
[..]
How big can stack hold on 32 bits machine? Should it hold between
500 megabytes and 1 gigabytes of memory?
It is usually controlled by the settings of your linker.
After you write a function, do you prefer to store one buffer to hold
1,024 bytes or 4,096 bytes?
I prefer to store what my algorithm tells me to store.
> Should 4,096 bytes be sufficient to hold
buffer or small array in stack?
Depends on the use of the buffer.
> Every time, function is called and it
takes CPU time to push empty buffer or small array into stack, do
algorithm, and pop used buffer or small array out of stack prior
exiting function is always slow.
Huh?
What option do you have? Do you prefer to create global variables to
hold buffer or small array into heap through reference or pointers
between function calls can be faster?
Use anything available to you. If the size of the buffer is known at
the compile-time, AND it's small enough, you can declare it locally in
some function. It's *usually* as fast as, or faster than, dynamic
allocation of arrays. If the size of the buffer is *not* known until
run-time, you have a choice, use 'new[]/delete[]' and do it yourself or
use standard containers.
For example:
[..snip..]
Please answer one question. How big can stack hold up to 500
megabytes on 32 bits machine?
Please re-phrase the question. I don't understand what it is you're
trying to learn about the stack (I presume you're talking about the
process' memory for objects with automatic storage duration).
V
--
I do not respond to top-posted replies, please don't ask