template<size_t total_size, size_t block_shift>
class mem_pool< total_size, block_shift >
*INDENT-OFF*Memory Pool
The VMM has to manage a lot of memory. This includes:
- Heap for new / delete
- Page pool for new / delete
- Virtual memory space for mapping memory
- Guest memory
The problem is, some of these memory pools point to pre-allocated space while others point to virtual memory that simply needs to be reserved for memory mapping (classic alloc vs map problem). In all cases, a contiguous memory space needs to be divided up and managed. This memory pool provides a really simple "next fit" algorithm for managing these different memory pools. Clearly there is room for improvement with this algorithm, but it should work for basic allocations. Further optimizations could be done using custom new / delete operators at the class level if needed until we can provide a more complicated algorithm.
- Parameters
-
total_size | total size in bytes of the memory pool |
block_shift | block size in bit shifts (i.e. 8 bytes == 3 bits) |
Definition at line 81 of file mem_pool.h.
template<size_t total_size, size_t block_shift>
Allocate Memory
Allocates memory from the memory pool whose size is greater than or equal to size. The memory pool will always be a multiple of 1 << block_shift. Memory allocated will always have an alignment equal to block_shift plus the starting address provided when creating the memory pool. For this reason, if a specific alignment is needed, ensure the start address has this same alignment when creating the memory pool
- Precondition
- expects: size > 0
-
expects: size <= total_size
- Postcondition
- ensures: ret != nullptr
- Parameters
-
size | the number of bytes to allocate |
- Returns
- the starting address of the
Definition at line 137 of file mem_pool.h.