VISH
0.2
|
A class which handles a chunk of memory. More...
#include </home/werner/origo/vish/memcore/Chunk.hpp>
A class which handles a chunk of memory.
It keeps initially allocated memory alive as long as the Chunk object lives, employing the STL vector<> class.
Basically, the Chunk class is a MemCore API to std::vector's with reference pointers, and an induced hierarchy. Induced hierarchy means that if an class B is derived from class A, then also a TypedChunk< B > will be derived from TypedChunk< A >. A TypedChunk<> is the base class of Chunk<> and provides all operator access to the data, which is actually stored in a Chunk<>.
For the hierarchy induction to work, a type trait BaseClass<> must exist for the given type. This is as simple as in this following code segment:
struct A { int i; }; struct B : A { }; template <> struct BaseClass<B> { typedef A result; };
In this case, the class hierarchy will be:
Chunk<B> : TypedChunk<B> : TypedChunk<A> : TypedChunkBase<A> : ChunkBase
A any element of this hierarchy can be converted into each other via assignment to a RefPtr<> of another element. For each typed chunk, a std::vector<> can be retrieved. Here, the Chunk can be accessed as an std::vector<B> as well as an std::vector<A> .
MemCore::Chunk::Chunk | ( | size_t | N, |
bool | ReserveOnly = false |
||
) | [inline] |
Constructor allocates a chunk of data.
N | Allocate that many objects. |
ReserveOnly | Reserve that many objects to be appended later. |