Jive reference manual
List of all members | Public Member Functions | Related Functions
jem::util::MallocAllocator Class Reference

Allocates memory chunks by calling the standard malloc function. More...

#include <jem/util/MallocAllocator.h>

Public Member Functions

 MallocAllocator (size_t itemSize)
 Creates a new allocator instance. More...
 
 ~MallocAllocator ()
 Destroys this allocator instance. More...
 
void * alloc ()
 Allocates a new memory chunk. More...
 
void dealloc (void *p)
 Deallocates a memory chunk. More...
 
void swap (MallocAllocator &rhs)
 Interchanges the internal state of allocators. More...
 

Related Functions

(Note that these are not member functions.)

void swap (MallocAllocator &lhs, MallocAllocator &rhs)
 Interchanges two allocators. More...
 

Detailed Description

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.

Constructor & Destructor Documentation

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.

Member Function Documentation

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
OutOfMemoryException- if no more memory is available.
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().
void jem::util::MallocAllocator::swap ( MallocAllocator rhs)

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
rhs- a FastAllocator instance.
See also
StdAllocator::swap().

Friends And Related Function Documentation

void swap ( MallocAllocator lhs,
MallocAllocator rhs 
)
related

This function is equivalent with

lhs.swap( rhs )