General Discussions

Static V/S Dynamic Memory Allocation

PH Bytes

Si. No Static Memory Allocation Dynamic Memory Allocation
1 Memory allocation happens at compile time Memory allocation happens at Run time
2 It applies to global variables, file scope variables, and variables qualified with static defined inside functions It applies to variables that allocate memory during runtime using memory allocation API’s
3 The size is fixed when the program is created Programmer can control the exact size and the lifetime of the memory locations
4 Memory allocated at compile time in stack or other data segments Memory is allocated during run-time in heap
5. This is used when the size of memory is variable and is known only during run-time This is used when the size of memory is static/constant and is known during compile-time
6. The compiler allocates the required memory space for a declared variable It uses functions such as malloc( ) or calloc( ) to get memory dynamically

View original post 84 more words

Advertisements

Let me Know What you Think!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s