Torque2D Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

Classes | Public Types | Public Member Functions | List of all members
DataChunker Class Reference

`#include <dataChunker.h>`

Inheritance diagram for DataChunker:

## Public Types
enum | { ChunkSize = 16376 }

## Public Member Functions
void * | alloc (S32 size)
void | freeBlocks ()
| DataChunker (S32 size=ChunkSize)
| ~DataChunker ()

## 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 blockss 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).

## Member Enumeration Documentation

anonymous enum

Enumerator
ChunkSize | Default size for chunks.

## Constructor & Destructor Documentation

DataChunker | ( | S32 | size = `ChunkSize` | ) |

Initialize using blocks of a given size.

One new block is allocated at constructor-time.

Parameters

  size | Size in bytes of the space to allocate for each block.

~DataChunker | ( |  | ) |

## Member Function Documentation

void * alloc | ( | S32 | size | ) |

Return a pointer to a chunk of memory from a pre-allocated block.

This memory goes away when you call freeBlocks.

This memory is word-aligned.

Parameters

  size | Size of chunk to return. This must be less than chunkSize or else an assertion will occur.

void freeBlocks | ( |  | ) |

Free all allocated memory blocks.

This invalidates all pointers returned from alloc().

The documentation for this class was generated from the following files:

- memory/dataChunker.h
- memory/dataChunker.cc