简体   繁体   中英

when real FREE the memory in STL

the STL's allocator use the memory pool tech, and it only add the memory needed deallocate into the free list, like this:

static void deallocate(void* __p, size_t __n)
{
    if (__n > (size_t) _MAX_BYTES)
    malloc_alloc::deallocate(__p, __n);
    else {
        _Obj* __STL_VOLATILE*  __my_free_list = _S_free_list + _S_freelist_index(__n);
        _Obj* __q = (_Obj*)__p;
        __q -> _M_free_list_link = *__my_free_list;
        *__my_free_list = __q;
    }
}

I want to know, when really FREE the free list?

There is no guarantee that the STL uses memory pools (although it is common).

It will depend on the implementation (compiler, library, version, OS, machine architecture, phase of the moon). A common answer is that memory allocated with new will only be returned to the operating system at program exit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM