是否有可能在C++中創建一個自定義分配器的作品簡直是這樣的:創建一個範圍自定義內存池/分配器?
{
// Limit memory to 1024 KB
ScopedMemoryPool memoryPool(1024 * 1024);
// From here on all heap allocations ('new', 'malloc', ...) take memory from the pool.
// If the pool is depleted these calls result in an exception being thrown.
// Examples:
std::vector<int> integers(10);
int a * = new int [10];
}
我找不到像這樣的Boost庫,或其他任何地方。
有沒有一個根本性的問題,使這不可能?
看一看的Boost.Pool庫。 'boost :: pool_allocator'和'boost :: fast_pool_allocator'可以用作'std :: vector'和其他容器的分配器。 – 2010-09-08 18:48:59