Implements a memory allocation algorithm that favors speed above fair memory use.
More...
#include <jem/util/FastAllocator.h>
Like the other allocator classes, the FastAllocator
class can be used to allocate equally-sized chunks of memory. It is the fastest allocator class because it does not free memory until its destructor is called. Use this allocator when you need performance and the total number of allocated memory chunks does not vary too much in time.
- See also
StandardAllocator
, MallocAllocator
.
jem::util::FastAllocator::FastAllocator |
( |
size_t |
itemSize | ) |
|
|
explicit |
Creates a FastAllocator
object that allocates memory chunks of itemSize bytes.
- Parameters
-
itemSize | - the size in bytes of the memory chunks to be allocated by this FastAllocator . |
- Precondition
itemSize > 0
jem::util::FastAllocator::~FastAllocator |
( |
| ) |
|
Frees the memory that has been allocated by this FastAllocator
object.
- Warning
- The lifetime of this allocator should exceed the lifetime of all the memory chunks that have been allocated by this allocator.
void* jem::util::FastAllocator::alloc |
( |
| ) |
|
Allocates a memory chunk of size equal to the argument passed to the constructor of this FastAllocator
object.
- Returns
- A pointer to a newly allocated memory chunk.
- Exceptions
-
void jem::util::FastAllocator::dealloc |
( |
void * |
p | ) |
|
Deallocates the memory chunk pointed to by the pointer p. This chunk must have been allocated by a call to the alloc()
member function.
The FastAllocator
class does not actually free the memory chunk, but marks it as not being used, so that it can be used again when alloc()
is called.
- Parameters
-
p | - a pointer to the memory chunk to be deallocated. |
- Precondition
- The memory chunk pointed to by p has been allocated by the member function
alloc()
.
Interchanges the internal state of this allocator with the rhs allocator. After calling this function, you must invoke the dealloc()
function on the rhs allocator to deallocate all memory chunks that have been obtained by invoking the alloc()
function on this allocator, and the other way around.
- Parameters
-
- See also
StdAllocator::swap()
.
This function is equivalent with:
lhs.swap( rhs )