How do malloc() and free() work?

后端 未结 13 2471
谎友^
谎友^ 2020-11-21 22:54

I want to know how malloc and free work.

int main() {
    unsigned char *p = (unsigned char*)malloc(4*sizeof(unsigned char));
    m         


        
13条回答
  •  太阳男子
    2020-11-21 23:28

    It's hard to say because the actual behaviour is different between different compilers/runtimes. Even debug/release builds have different behaviour. Debug builds of VS2005 will insert markers between allocations to detect memory corruption, so instead of a crash, it will assert in free().

提交回复
热议问题