Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

DynObjAlloc Class Template Reference

A fast allocator of objects. More...

#include <DynMemAlloc.h>

Inheritance diagram for DynObjAlloc

Inheritance graph
[legend]
Collaboration diagram for DynObjAlloc:

Collaboration graph
[legend]
List of all members.

Public Methods

 DynObjAlloc (ppSizeT initialCapacity = 0, ppSizeT capacityGrowth = 16)
 Refer to the constructor of DynMemAlloc for an explanation, as both parameters are simply passed on to that. Notice, though, that both parameters are multiplied by sizeof(OBJ) first.

void* Allocate ()
 This method is a convinience method only. It calls Allocate(sizeof(OBJ)) and returns the return value. The convinience lies in that you don't have to pass the sizeof(OBJ) as a parameter. This parameterless overload of Allocate() does not hide the single parameter overload enherited from DynMemAlloc.

OBJ* ConstructAllocate ()
 This method allocates memory for an object of type OBJ via the DynMemAlloc method Allocate(). This migth result in an exception of type bad_alloc that ConstructAllocate() does not catch. ConstructAllocate() also constructs the allocated memory using the default constructor. If this constructor results in an exception, ConstructAllocate() catches it, deallocates the allocated memory, and rethrows the exception. Finally, ConstructAllocate() returns the address of the newly allocated and constructed object.


Detailed Description

template<class OBJ> template class DynObjAlloc

A fast allocator of objects.

DynObjAlloc behaves very much like its parent class, DynMemAlloc. Actually, it behaves exactly like DynMemAlloc, except for the fact that it implements two additional methods, ConstructAllocate() and Allocate().

Notice that DynObjAlloc does not provide for a way to destruct objects. This is because the underlying concept of DynObjAlloc makes it impossible to know what memory addresses to destruct. If you plan to use DynObjAlloc, you will have to destruct all objects by yourself before calling Reset() or destructing DynObjAlloc.

As the name migth suggest, ConstructAllocate() not only allocates memory for an object of type OBJ, but also constructs this memory using the default constructor.

Allocate() is a parameterless utility method.

The basic concept is exactly the same for both DynObjAlloc and DynMemAlloc. Refer to DynMemAlloc to get a more detailed description of how both of these classes work.


The documentation for this class was generated from the following file:
Generated at Mon Nov 27 01:46:46 2000 for LibPenguinPlay by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000