memory - Heap - How free bytes are tracked? -
i reading heap , stack usage , have question heap , dynamically allocated memory.
how/where heap memory used application known used or availabe?
what see in explanation of dynamic allocation :
int *p; p = (int*)malloc(sizeof(int));/* space in heap allocated store int*/ p = (int*)malloc(sizeof(int));/* p points space in heap ; first allocated space lost, causing memory leak*/
i understand /* comments */ wrote in code don't understand first space "lost" came 2 ideas:
- everytime there dynamic allocation, "something" must keep track of space reserved in memory (address of first byte , size of space allocated) : list updated @ each dynamic allocation.
- or there sort of flag each byte saying free or used application.
in way, call free function would, first idea, update list removing address of bytes or second 1 change flags.
thank time.
Comments
Post a Comment