The implementation exploits the block's alignment to compute the block control for pointers being released, meaning there is no per-chip space overhead other than the per-block bitmap indicating which chips are available.
One caveat of the this approach is that the caller is responsible to ensure that any chip passed to release() is actually part of a block (presumably by verifying that the address range is inside an appropriate memory pool). In practice this is done by calling dynpool::validate_ptr(chip-ptr).
This class manages memory only very loosely: distributing and accepting the return of chip_size -sized chips. At no time does it access any of the memory it manages.
Definition at line 197 of file mem_block.h.
Public Member Functions | |
NORET | block_of_chips (size_t chip_size, size_t chip_count, size_t block_size) |
Constructor. The memory is assumed to be block_size bytes long and must be aligned on a block_size -sized boundary. The constructor checks the arithmetic to make sure chip_count chips of size chip_size fit into the block. The block of chips is the array _data. | |
chip_t | acquire_chip (size_t chip_size, size_t chip_count, size_t block_size) |
Constructor. Acquire one chip. The chip_size, chip_count (chips/block) and block_size are template arguments and do not change. | |
void | recycle () |
Make zombies usable. | |
chip_t | get (size_t idx, size_t chip_size) |
Return address of a single chip at given index. | |
Static Public Member Functions | |
static void | release_chip (chip_t ptr, size_t chip_size, size_t chip_count, size_t block_size) |
This is static because it uses pointer arithmetic on the ptr to find out to which block of chips this chip belongs; then it releases the chip through that block. The assumption is that the block cannot have been released to the underlying allocator because the chip is still in use. | |
Public Attributes | |
block_bits | _bits |
block_list * | _owner |
block_of_chips * | _next |
static void memory_block::block_of_chips::release_chip | ( | chip_t | ptr, | |
size_t | chip_size, | |||
size_t | chip_count, | |||
size_t | block_size | |||
) | [static] |
This is static because it uses pointer arithmetic on the ptr to find out to which block of chips this chip belongs; then it releases the chip through that block. The assumption is that the block cannot have been released to the underlying allocator because the chip is still in use.
Referenced by block_pool< T, Pool, MaxBytes >::release().
Here is the caller graph for this function: