- fixed FMemArena to always return 16 byte aligned pointers.

Unfortunately this turned out harder than expected because of FSharedStringArena making some strong assumptions about the underlying implementation.
This commit is contained in:
Christoph Oelckers 2018-06-04 21:50:36 +02:00
parent af3d17af8b
commit 2f6dc46f14
2 changed files with 10 additions and 3 deletions

View file

@ -46,6 +46,7 @@ struct FMemArena::Block
Block *NextBlock;
void *Limit; // End of this block
void *Avail; // Start of free space in this block
void *alignme; // align to 16 bytes.
void Reset();
void *Alloc(size_t size);
@ -94,7 +95,7 @@ FMemArena::~FMemArena()
//
//==========================================================================
void *FMemArena::Alloc(size_t size)
void *FMemArena::iAlloc(size_t size)
{
Block *block;
@ -110,6 +111,11 @@ void *FMemArena::Alloc(size_t size)
return block->Alloc(size);
}
void *FMemArena::Alloc(size_t size)
{
return iAlloc((size + 15) & ~15);
}
//==========================================================================
//
// FMemArena :: FreeAll
@ -316,7 +322,7 @@ FString *FSharedStringArena::Alloc(const FString &source)
strnode = FindString(source, source.Len(), hash);
if (strnode == NULL)
{
strnode = (Node *)FMemArena::Alloc(sizeof(Node));
strnode = (Node *)iAlloc(sizeof(Node));
::new(&strnode->String) FString(source);
strnode->Hash = hash;
hash %= countof(Buckets);
@ -351,7 +357,7 @@ FString *FSharedStringArena::Alloc(const char *source, size_t strlen)
strnode = FindString(source, strlen, hash);
if (strnode == NULL)
{
strnode = (Node *)FMemArena::Alloc(sizeof(Node));
strnode = (Node *)iAlloc(sizeof(Node));
::new(&strnode->String) FString(source, strlen);
strnode->Hash = hash;
hash %= countof(Buckets);

View file

@ -54,6 +54,7 @@ protected:
Block *AddBlock(size_t size);
void FreeBlockChain(Block *&top);
void *iAlloc(size_t size);
Block *TopBlock;
Block *FreeBlocks;