mirror of
https://github.com/tribes2/engine.git
synced 2026-01-20 19:54:46 +00:00
54 lines
1.1 KiB
C++
54 lines
1.1 KiB
C++
//-----------------------------------------------------------------------------
|
|
// V12 Engine
|
|
//
|
|
// Copyright (c) 2001 GarageGames.Com
|
|
// Portions Copyright (c) 2001 by Sierra Online, Inc.
|
|
//-----------------------------------------------------------------------------
|
|
|
|
#ifndef _DATACHUNKER_H_
|
|
#define _DATACHUNKER_H_
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
class DataChunker
|
|
{
|
|
public:
|
|
enum {
|
|
ChunkSize = 16376
|
|
};
|
|
|
|
private:
|
|
struct DataBlock
|
|
{
|
|
DataBlock *next;
|
|
U8 *data;
|
|
S32 curIndex;
|
|
DataBlock(S32 size);
|
|
~DataBlock();
|
|
};
|
|
DataBlock *curBlock;
|
|
S32 chunkSize;
|
|
public:
|
|
void *alloc(S32 size);
|
|
void freeBlocks();
|
|
|
|
DataChunker(S32 size=ChunkSize);
|
|
~DataChunker();
|
|
};
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
template<class T>
|
|
class Chunker: private DataChunker
|
|
{
|
|
public:
|
|
Chunker(S32 size = DataChunker::ChunkSize) : DataChunker(size) {};
|
|
T* alloc() { return reinterpret_cast<T*>(DataChunker::alloc(S32(sizeof(T)))); }
|
|
void clear() { freeBlocks(); };
|
|
};
|
|
|
|
|
|
#endif
|