what happens when tried to free memory allocated by heap manager, which allocates more than asked for?

后端 未结 5 2144
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-15 10:45

This question was asked to me in an interview.

Suppose char *p=malloc(n) assigns more than n,say N bytes of memory are allocated and free(p) is used to free the memory a

5条回答
  •  余生分开走
    2021-02-15 11:03

    Other answers have explained well how the block size is handled. To find out how much memory is freed, the only solution I can think of is to call mallinfo() before and after the free.

提交回复
热议问题