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

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -