Original Post
This is my stack allocator:
StackAllocator.cpp
However the allocate method doesn't return aligned pointers. How should I write allocate() method to return aligned pointers?
#include <stdlib.h>
#include <cstdint>
typedef uintptr_t Marker;
namespace Loodus
{
class StackAllocator
{
public:
StackAllocator(U32 size);
Marker allocate(U32 size);
void freeToMarker(Marker marker);
void clear();
private:
Marker m_InitialPosition;
Marker m_CurrentPosition;
};
};
StackAllocator.cpp
#include "StackAllocator.h"
using namespace Loodus;
StackAllocator::StackAllocator(U32 size)
{
m_InitialPosition = (Marker) malloc(size);
}
Marker StackAllocator::allocate(U32 size)
{
Marker m = m_CurrentPosition;
m_CurrentPosition += size;
return m;
}
void StackAllocator::freeToMarker(Marker marker)
{
m_CurrentPosition = marker;
}
void StackAllocator::clear()
{
m_CurrentPosition = m_InitialPosition;
}
However the allocate method doesn't return aligned pointers. How should I write allocate() method to return aligned pointers?