且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何强制我的std :: map释放内存使用?

更新时间:2023-02-02 15:08:25

m.clear()将内存释放回堆,实现不释放回到操作系统(即使他们可以,诸如碎片的问题使它很难)。

m.clear() releases memory back to the heap, but it's common for heap implementations to not release that back to the OS (even when they can, issues such as fragmentation make it hard).

这是默认分配器如何工作,如果你' ve为地图指定了自己的分配器,它可能有自己的缓存。但是,即使在这种情况下,它也应该被缓存,以便立即重用。

This is how the default allocator works, if you've specified your own allocator for the map, it might have its own cache. However, even in that case, it should be cached in order to be reused immediately anyway.

地图没有容量vs大小矢量的概念。

Maps don't have a concept of capacity vs size the way vectors do.