p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   .NET 4 and Visual Studio 2010 General Discussions (http://p2p.wrox.com/forumdisplay.php?f=579)
-   -   Difference between Stack and Heap Memory Storage (http://p2p.wrox.com/showthread.php?t=87404)

Ashish_Sharma_1982 April 28th, 2012 05:01 PM

Difference between Stack and Heap Memory Storage
 
In terms of Stack storage, what is the meaning of:
"An Integer or Decimal value needs the same number of Bytes to store data, regardless of the actual value."?

lee_suko March 15th, 2016 03:57 AM

Stack and Heap Memory Storage
 
Variables allocated on the stack are stored directly to the memory and access to this memory is very fast, and it's allocation is dealt with when the program is compiled. When a function or a method calls another function which in turns calls another function etc., the execution of all those functions remains suspended until the very last function returns its value. The stack is always reserved in a LIFO order, the most recently reserved block is always the next block to be freed. This makes it really simple to keep track of the stack, freeing a block from the stack is nothing more than adjusting one pointer.
Variables allocated on the heap have their memory allocated at run time and accessing this memory is a bit slower, but the heap size is only limited by the size of virtual memory . Element of the heap have no dependencies with each other and can always be accessed randomly at any time. You can allocate a block at any time and free it at any time. This makes it much more complex to keep track of which parts of the heap are allocated or free at any given time. More about...Stack and Heap


Lee



All times are GMT -4. The time now is 08:23 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.