How does realloc know how much to copy?

后端 未结 5 1095
庸人自扰
庸人自扰 2020-12-11 15:52

how does realloc know the size of original data?

 void *realloc(void *ptr, size_t size);

So, if the implementation is like this:

         


        
5条回答
  •  一整个雨季
    2020-12-11 16:47

    Why don't you just look up how malloc/calloc/realloc/free is implemented in the C standard library you're using?

    Or, if you don't have access to the source code, look at how it's implemented in one of the open-source C standard libraries.

提交回复
热议问题