简体   繁体   English

当真正释放STL中的内存时

[英]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: STL的分配器使用内存池技术,它只将需要释放的内存添加到空闲列表中,如下所示:

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). 无法保证STL使用内存池(尽管很常见)。

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. 一个常见的答案是,使用new分配的内存只会在程序退出时返回给操作系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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