N
Nephi Immortal
I always agree that stack is very effectively fast to push built-in
type variables into stack and pop them out of it between function
calls. Small stack size is very important. I have no idea how big it
can hold hundreds or thousands of variables.
It is possible to overflow the stack size if you use too many buffers
or small arrays. Hundreds or thousands of buffers or small arrays are
pushed into stack if you call 100 function calls before stack grows
bigger fast. Error assert message is triggered to report stack
overflow.
How big can stack hold on 32 bits machine? Should it hold between
500 megabytes and 1 gigabytes of memory?
After you write a function, do you prefer to store one buffer to hold
1,024 bytes or 4,096 bytes? Should 4,096 bytes be sufficient to hold
buffer or small array in stack? 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.
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?
For example:
void foo( const char *dest )
{
char buffer[ 1024 ]; // pusb 1,024 bytes into stack
// char *buffer = g_buffer; // set pointer to buffer in global scope
char *pBuffer = buffer;
char *pDest = dest;
do
{
*pBuffer = *pDest;
++pBuffer;
++pDest;
}
while( *pDest != ‘\0’ );
*pBuffer = ‘\0’;
// Create more buffers or small arrays and copy
// them into one buffer
// Do algorithm
cout << pBuffer << endl;
// Pop all buffers and small arrays out of stack
// and exit function
}
Perhaps, you suggest to use heap in global scope.
// global scope
char *buffer = 0; // or you can use string class or vector class
int main()
{
buffer = new char[ 4096 ];
foo( buffer );
delete [] buffer;
// you can replace new / delete to string class or vector class
}
Please answer one question. How big can stack hold up to 500
megabytes on 32 bits machine?
type variables into stack and pop them out of it between function
calls. Small stack size is very important. I have no idea how big it
can hold hundreds or thousands of variables.
It is possible to overflow the stack size if you use too many buffers
or small arrays. Hundreds or thousands of buffers or small arrays are
pushed into stack if you call 100 function calls before stack grows
bigger fast. Error assert message is triggered to report stack
overflow.
How big can stack hold on 32 bits machine? Should it hold between
500 megabytes and 1 gigabytes of memory?
After you write a function, do you prefer to store one buffer to hold
1,024 bytes or 4,096 bytes? Should 4,096 bytes be sufficient to hold
buffer or small array in stack? 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.
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?
For example:
void foo( const char *dest )
{
char buffer[ 1024 ]; // pusb 1,024 bytes into stack
// char *buffer = g_buffer; // set pointer to buffer in global scope
char *pBuffer = buffer;
char *pDest = dest;
do
{
*pBuffer = *pDest;
++pBuffer;
++pDest;
}
while( *pDest != ‘\0’ );
*pBuffer = ‘\0’;
// Create more buffers or small arrays and copy
// them into one buffer
// Do algorithm
cout << pBuffer << endl;
// Pop all buffers and small arrays out of stack
// and exit function
}
Perhaps, you suggest to use heap in global scope.
// global scope
char *buffer = 0; // or you can use string class or vector class
int main()
{
buffer = new char[ 4096 ];
foo( buffer );
delete [] buffer;
// you can replace new / delete to string class or vector class
}
Please answer one question. How big can stack hold up to 500
megabytes on 32 bits machine?