answersLogoWhite

0

Static variables are allocated upon the stack and exist from compile time. Dynamic variables are created on the heap and only exist at runtime. Since the stack exists within the program's data segment, the more static variables you declare the larger your executable needs to be to cater for them. For that reason it's best to keep static variables to a minimum. Large and complex structures are best allocated dynamically, particularly if the size of the structure is not of fixed size. The heap is effectively unlimited* in size thus can easily accommodate extremely large structures as and when they are required, destroying them when they are no longer needed, rather than keeping them in memory at all times.

*32-bit systems have a maximum limit of 4GB virtual memory (including the paging file), which includes graphics card memory and peripheral memory, all of which must be mapped within the 4GB address space (thus reducing available memory accordingly). 64-bit systems have no such limitations and will use as much virtual memory (disk space) as is required to meet memory requirements. Although there is effectively no limit to the amount of physical memory that can be addressed, 64-bit systems still have an upper limit due to physical constraints. Indeed, there isn't enough RAM in the world to fill just one 64-bit system to its maximum capacity, never mind all of them.

User Avatar

Wiki User

11y ago

What else can I help you with?