- 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.

(cherry picked from commit 2f6dc46f14)
This commit is contained in:
Christoph Oelckers 2018-06-04 21:50:36 +02:00 committed by drfrag666
parent 74f4c8a6dd
commit dc43bc5f0e
2 changed files with 10 additions and 3 deletions

View file

@ -48,6 +48,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);
@ -96,7 +97,7 @@ FMemArena::~FMemArena()
//
//==========================================================================
void *FMemArena::Alloc(size_t size)
void *FMemArena::iAlloc(size_t size)
{
Block *block;
@ -112,6 +113,11 @@ void *FMemArena::Alloc(size_t size)
return block->Alloc(size);
}
void *FMemArena::Alloc(size_t size)
{
return iAlloc((size + 15) & ~15);
}
//==========================================================================
//
// FMemArena :: FreeAll
@ -318,7 +324,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);
@ -353,7 +359,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;