Skip to content

Instantly share code, notes, and snippets.

@luyao795
Created August 24, 2017 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luyao795/82190b84bf6a8abd139cb2680435e207 to your computer and use it in GitHub Desktop.
Save luyao795/82190b84bf6a8abd139cb2680435e207 to your computer and use it in GitHub Desktop.
Header file for Fixed Size Allocator
#ifndef FIXEDSIZEALLOCATOR_H
#define FIXEDSIZEALLOCATOR_H
#include "BitArray.h"
namespace Engine
{
class FixedSizeAllocator
{
public:
FixedSizeAllocator(const size_t size, const size_t numBlocks, BlockAllocator* blockAllocator);
void destroy();
void* allocate(size_t size);
void free(void* pointer);
bool isInRange(void* pointer, const void* left, const void* right);
size_t getBlockIndex(void* pointer);
size_t getBlockSize() const;
size_t getBlockNumber() const;
void* getBlockStart() const;
void* getBlockOver() const;
BitArray* getBitArray();
private:
~FixedSizeAllocator();
BitArray* bitArray;
size_t blockSize;
size_t numBlock;
static BlockAllocator* allocator;
void* blockStart;
};
}
#endif // !FIXEDSIZEALLOCATOR_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment