1

Why would one choose to use ordered_free() instead of free() when using Boost pool? Assumedly ordered_free() is always O(n) while free() should be O(1). Is there a benefit where there is less fragmentation? My use case is using Boost pool in a high-performance server that will run all day long with lots of allocations and deallocations throughout the day.

4

1 に答える 1

4

The documentation answers this question:

An ordered pool maintains it's free list in order of the address of each free block - this is the most efficient way if you're likely to allocate arrays of objects. However, freeing an object can be O(N) in the number of currently free blocks which can be prohibitively expensive in some situations.

An unordered pool does not maintain it's free list in any particular order, as a result allocation and freeing single objects is very fast, but allocating arrays may be slow (and in particular the pool may not be aware that it contains enough free memory for the allocation request, and unnecessarily allocate more memory).

于 2012-08-28T17:43:50.620 に答える