开发者

Is there any recycling pool structure in C++ Boost?

I need a pool struct that can reuse/recycle the memory after usage, i.e., DON'T do any allocation or deallocation on-the-fly (although you still need to allocate the memory at the moment when the program starts)

开发者_运维百科Boost.Pool does not support such a mechanism; is there any alternative?


What about just allocating a lot of space for the pool as soon as you create it? The function pool::orderedMalloc(n) seems to do just that.

Yes, you're still allocating at "runtime", but only as the process starts.


The standard heap mechanisms reuse memory after it is released; a single address range may be used by many different values over the lifetime of a program. However, as you suggest, such mechanisms do acquire memory from the system as needed at runtime.

If you need to preallocate a suitable size chunk of memory and then dole out allocations from that, you'd be looking at sensitive stuff like overloading global operator new and its friends to do allocation out of the preallocated space, presumably throwing exceptions when the preallocated space runs out. [Don't try this without adult supervision - and don't look to me for that supervision; I'm a chicken!]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜