Skip to content
Snippets Groups Projects
Commit 277ac7c7 authored by Terraneo Federico's avatar Terraneo Federico
Browse files

Starting the implementation of the pool allocator

parent 0846e98f
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,7 @@ SUBDIRS := miosix ...@@ -14,7 +14,7 @@ SUBDIRS := miosix
## List here your source files (both .s, .c and .cpp) ## List here your source files (both .s, .c and .cpp)
## ##
SRC := \ SRC := \
main.cpp main.cpp pool_allocator.cpp
## ##
## List here additional static libraries with relative path ## List here additional static libraries with relative path
......
#include "pool_allocator.h"
PoolAllocator::PoolAllocator(unsigned int *poolBase, unsigned int poolSize)
: poolBase(poolBase), poolSize(poolSize)
{
bitmap=new unsigned int[poolSize/blockSize/sizeof(unsigned int)];
}
unsigned int *PoolAllocator::allocate(int size)
{
//TODO : align this, and validate size to prevent wraparound
unsigned int offset=0;
if(poolBase % size) offset=size-(poolBase % size);
int startBit=offset/blockSize;
}
void PoolAllocator::deallocate(unsigned int *ptr)
{
}
PoolAllocator::~PoolAllocator()
{
delete[] bitmap;
}
#include <map>
#ifndef POOL_ALLOCATOR
#define POOL_ALLOCATOR
class PoolAllocator
{
public:
PoolAllocator(unsigned int *poolBase, unsigned int poolSize);
unsigned int *allocate(int size);
void deallocate(unsigned int *ptr);
~PoolAllocator();
static const int blockSize=1024;
private:
PoolAllocator(const PoolAllocator&);
PoolAllocator& operator= (const PoolAllocator&);
unsigned int *bitmap;
unsigned int *poolBase;
unsigned int poolSize;
std::map<unsigned int*,unsigned int> allocatedBlocks;
};
#endif //POOL_ALLOCATOR
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment