Home » » memory management in c language

memory management in c language

Memory management funda in every languages r different. Java uses garbage collection to deallocates the unused object. When the particular object has no reference then jvm calls gc to run. Gc deallocates that particular memory acquired by object.

Now what's the difference in C for memory management.

Memory can be allocated in different memory segments

-> Heap
-> Stack
-> Class


1)Heap is for dynamic memory allocation. Likewise we want to allocate runtime memory for object. We can give using malloc or calloc function defined in stdlib.h library.

Actually, we use heap for linked list, trees, bfs, dfs and queues.

simple example   int *p= (int *)malloc(sizeof(int));

it is allocating sizeof int to pointer p at runtime.


2)Stack - Stack uses lifo algorithm last in first out. Compiler uses stack memory for local variables, functions and arguments.


3)Class Area - This particular area use for holding static members of any class.


Share this article :

0 comments:

Post a Comment

 
My Other Websites : Ad Networks | Games Copyright © 2014. Study Depth - All Rights Reserved