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

后端 未结 5 2112
忘了有多久
忘了有多久 2021-02-15 10:48

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:07

    This is the default behavior of malloc. It will return NULL or a pointer to a section of memory at least as long as the one you asked for. So yes free must be able to handle getting rid of memory longer than what was asked for.

    Finding out how much memory was actually free or allocated is a platform specific question.

提交回复
热议问题