Why free() doesn't really frees memory?

前端 未结 4 2227
情歌与酒
情歌与酒 2020-12-01 22:45

i\'m doing some tests allocating and deallocating memory. This is the code i\'m using:

#include 
#include 

#define WAVE_SIZE          


        
4条回答
  •  一整个雨季
    2020-12-01 22:59

    When memory is allocated and later free'd, that memory still stays with the process but is marked as free so it can be allocated again. This is because otherwise the operating system have to alter the virtual memory mapping of the process each time you call malloc or free, which takes time.

提交回复
热议问题