mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-01-31 04:20:34 +00:00
- 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:
parent
74f4c8a6dd
commit
dc43bc5f0e
2 changed files with 10 additions and 3 deletions
|
@ -48,6 +48,7 @@ struct FMemArena::Block
|
||||||
Block *NextBlock;
|
Block *NextBlock;
|
||||||
void *Limit; // End of this block
|
void *Limit; // End of this block
|
||||||
void *Avail; // Start of free space in this block
|
void *Avail; // Start of free space in this block
|
||||||
|
void *alignme; // align to 16 bytes.
|
||||||
|
|
||||||
void Reset();
|
void Reset();
|
||||||
void *Alloc(size_t size);
|
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;
|
Block *block;
|
||||||
|
|
||||||
|
@ -112,6 +113,11 @@ void *FMemArena::Alloc(size_t size)
|
||||||
return block->Alloc(size);
|
return block->Alloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *FMemArena::Alloc(size_t size)
|
||||||
|
{
|
||||||
|
return iAlloc((size + 15) & ~15);
|
||||||
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// FMemArena :: FreeAll
|
// FMemArena :: FreeAll
|
||||||
|
@ -318,7 +324,7 @@ FString *FSharedStringArena::Alloc(const FString &source)
|
||||||
strnode = FindString(source, source.Len(), hash);
|
strnode = FindString(source, source.Len(), hash);
|
||||||
if (strnode == NULL)
|
if (strnode == NULL)
|
||||||
{
|
{
|
||||||
strnode = (Node *)FMemArena::Alloc(sizeof(Node));
|
strnode = (Node *)iAlloc(sizeof(Node));
|
||||||
::new(&strnode->String) FString(source);
|
::new(&strnode->String) FString(source);
|
||||||
strnode->Hash = hash;
|
strnode->Hash = hash;
|
||||||
hash %= countof(Buckets);
|
hash %= countof(Buckets);
|
||||||
|
@ -353,7 +359,7 @@ FString *FSharedStringArena::Alloc(const char *source, size_t strlen)
|
||||||
strnode = FindString(source, strlen, hash);
|
strnode = FindString(source, strlen, hash);
|
||||||
if (strnode == NULL)
|
if (strnode == NULL)
|
||||||
{
|
{
|
||||||
strnode = (Node *)FMemArena::Alloc(sizeof(Node));
|
strnode = (Node *)iAlloc(sizeof(Node));
|
||||||
::new(&strnode->String) FString(source, strlen);
|
::new(&strnode->String) FString(source, strlen);
|
||||||
strnode->Hash = hash;
|
strnode->Hash = hash;
|
||||||
hash %= countof(Buckets);
|
hash %= countof(Buckets);
|
||||||
|
|
|
@ -54,6 +54,7 @@ protected:
|
||||||
|
|
||||||
Block *AddBlock(size_t size);
|
Block *AddBlock(size_t size);
|
||||||
void FreeBlockChain(Block *&top);
|
void FreeBlockChain(Block *&top);
|
||||||
|
void *iAlloc(size_t size);
|
||||||
|
|
||||||
Block *TopBlock;
|
Block *TopBlock;
|
||||||
Block *FreeBlocks;
|
Block *FreeBlocks;
|
||||||
|
|
Loading…
Reference in a new issue