Pyrogenesis trunk
|
#include "precompiled.h"
#include "lib/allocators/pool.h"
#include "lib/alignment.h"
#include "lib/allocators/freelist.h"
#include "lib/timer.h"
Classes | |
struct | Allocators::BasicPoolTest< Storage > |
Namespaces | |
namespace | Allocators |
Functions | |
void | Allocators::TestPool () |
TIMER_ADD_CLIENT (tc_pool_alloc) | |
Status | pool_create (Pool *p, size_t max_size, size_t el_size) |
Ready Pool for use. More... | |
Status | pool_destroy (Pool *p) |
free all memory (address space + physical) that constitutes the given Pool. More... | |
bool | pool_contains (const Pool *p, void *el) |
indicate whether a pointer was allocated from the given pool. More... | |
void * | pool_alloc (Pool *p, size_t size) |
Dole out memory from the pool. More... | |
void | pool_free (Pool *p, void *el) |
Make a fixed-size element available for reuse in the given Pool. More... | |
void | pool_free_all (Pool *p) |
"free" all user allocations that ensued from the given Pool. More... | |
size_t | pool_committed (Pool *p) |
Return the number of bytes committed in the pool's backing array. More... | |
void * pool_alloc | ( | Pool * | p, |
size_t | size | ||
) |
Dole out memory from the pool.
exhausts the freelist before returning new entries to improve locality.
p | Pool* |
size | bytes to allocate; ignored if pool_create's el_size was not 0. |
size_t pool_committed | ( | Pool * | p | ) |
Return the number of bytes committed in the pool's backing array.
This is roughly the number of bytes allocated in this pool plus the unused freelist entries.
p | Pool* |
bool pool_contains | ( | const Pool * | p, |
void * | el | ||
) |
indicate whether a pointer was allocated from the given pool.
this is useful for callers that use several types of allocators.
p | Pool* |
el |
Ready Pool for use.
p | Pool* |
max_size | Max size [bytes] of the Pool; this much (rounded up to next page multiple) virtual address space is reserved. no virtual memory is actually committed until calls to pool_alloc. |
el_size | Number of bytes that will be returned by each pool_alloc (whose size parameter is then ignored). Can be 0 to allow variable-sized allocations, but pool_free is then unusable. |
free all memory (address space + physical) that constitutes the given Pool.
future alloc and free calls on this pool will fail. continued use of the allocated memory (*) is impossible because it is marked not-present via MMU. (* no matter if in freelist or unused or "allocated" to user)
p | Pool* |
void pool_free | ( | Pool * | p, |
void * | el | ||
) |
Make a fixed-size element available for reuse in the given Pool.
this is not allowed if the Pool was created for variable-size elements. rationale: avoids having to pass el_size here and compare with size when allocating; also prevents fragmentation and leaking memory.
p | Pool* |
el | Element returned by pool_alloc. |
void pool_free_all | ( | Pool * | p | ) |
"free" all user allocations that ensued from the given Pool.
this resets it as if freshly pool_create-d, but doesn't release the underlying reserved virtual memory.
p | Pool* |
TIMER_ADD_CLIENT | ( | tc_pool_alloc | ) |