News SF.net Project Frequently Asked Questions Documentation Downloads Mailing Lists How to Contribute

SourceForge.net Logo

Changing the way games are made and played.

TNL::DataChunker class Reference

TNL::DataChunker Class Reference

#include <tnlDataChunker.h>

Inheritance diagram for TNL::DataChunker:

TNL::ClassChunker< T >

Detailed Description

Implements a chunked data allocater.

Calling new/malloc all the time is a time consuming operation. Therefore, we provide the DataChunker, which allocates memory in blocks of chunkSize (by default 16k, see ChunkSize, though it can be set in the constructor), then doles it out as requested, in chunks of up to chunkSize in size.

It will assert if you try to get more than ChunkSize bytes at a time, and it deals with the logic of allocating new blocks and giving out word-aligned chunks.

Note that new/free/realloc WILL NOT WORK on memory gotten from the DataChunker. This also only grows (you can call freeBlocks to deallocate and reset things).


Public Types

enum  { ChunkSize = 16376 }

Public Member Functions

void * alloc (S32 size)
 allocate a pointer to memory of size bytes from the DataChunker

void freeBlocks ()
 free all pages currently allocated in the DataChunker

 DataChunker (S32 size=ChunkSize)
 Construct a DataChunker with a page size of size bytes.

 ~DataChunker ()
void swap (DataChunker &d)
 Swaps the memory allocated in one data chunker for another.


Private Attributes

DataBlockcurBlock
 current page we're allocating data from

S32 chunkSize
 The size allocated for each page in the DataChunker.


Member Enumeration Documentation

anonymous enum
 

Enumeration values:
ChunkSize  Default size of each DataBlock page in the DataChunker.


Constructor & Destructor Documentation

TNL::DataChunker::DataChunker S32  size = ChunkSize  ) 
 

Construct a DataChunker with a page size of size bytes.

TNL::DataChunker::~DataChunker  ) 
 


Member Function Documentation

void* TNL::DataChunker::alloc S32  size  ) 
 

allocate a pointer to memory of size bytes from the DataChunker

void TNL::DataChunker::freeBlocks  ) 
 

free all pages currently allocated in the DataChunker

Reimplemented in TNL::ClassChunker< T >, TNL::ClassChunker< BucketEntry >, and TNL::ClassChunker< EventNote >.

void TNL::DataChunker::swap DataChunker d  )  [inline]
 

Swaps the memory allocated in one data chunker for another.

This can be used to implement packing of memory stored in a DataChunker.


Field Documentation

DataBlock* TNL::DataChunker::curBlock [private]
 

current page we're allocating data from

If the data size request is greater than the memory space currently available in the current page, a new page will be allocated.

S32 TNL::DataChunker::chunkSize [private]
 

The size allocated for each page in the DataChunker.