Implementation of Realloc in C

后端 未结 3 642
猫巷女王i
猫巷女王i 2020-12-20 02:31
int getmin(int a, int b)
{
    return a

        
3条回答
  •  南方客
    南方客 (楼主)
    2020-12-20 03:04

    malloc does not initialize memory to zero. (calloc is the equivalent that does.) If you are seeing things set to zero, it's accidental.

    I believe the library version of realloc uses length information in the heap that is not directly available. (And it may overestimate the original allocation, which means it might copy a little extra memory when using realloc to expand the allocation. This generally has no effect.)

    realloc likely doesn't do a copy when shrinking an allocation.

    Also, I should note that in same cases, you don't have to do a copy even when realloc increases the size, for example, if the next block in the heap is free.

提交回复
热议问题