Allocates memory chunks by calling the standard malloc function.
More...
#include <jem/util/MallocAllocator.h>
The MallocAllocator
class can be used to allocate equally-sized chunks of memory. It is not particularly fast because it simply calls the standard C library function malloc()
to allocate each memory chunk. Use this allocator class if you have a special implementation of malloc()
that you want to use.
- See also
StandardAllocator
, FastAllocator
.
jem::util::MallocAllocator::MallocAllocator |
( |
size_t |
itemSize | ) |
|
|
explicit |
Creates a MallocAllocator
object that allocates memory chunks of itemSize bytes.
- Parameters
-
itemSize | - the size in bytes of the memory chunks to be allocated. |
- Precondition
itemSize > 0
jem::util::MallocAllocator::~MallocAllocator |
( |
| ) |
|
This destructor does nothing since the MallocAllocator
does not maintain any internal state.
void* jem::util::MallocAllocator::alloc |
( |
| ) |
|
Allocates a memory chunk of size equal to the argument passed to the constructor of this MallocAllocator
object. This member function simply calls the standard C library function malloc()
to allocate the memory chunk.
- Returns
- A pointer to a newly allocated memory chunk.
- Exceptions
-
void jem::util::MallocAllocator::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.
- 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 )