use a memory arena for allocating code generation nodes.
- Since the number of small allocations here is extremely high this will help a lot to prevent fragmentation and since most nodes are collected up front and this is done when no large resources are being loaded it won't cause heap spikes. let Emit methods delete FxExpression arrays when they are done. - For some reason the deletion process does not work 100%, there are always some nodes left behind and so far I haven't found them. This ensures that these arrays do not live any longer than needed.
This commit is contained in:
parent
e0bd6a2c0a
commit
a60bdc2bfb
9 changed files with 205 additions and 200 deletions
|
|
@ -43,8 +43,6 @@
|
|||
#include "c_dispatch.h"
|
||||
#include "zstring.h"
|
||||
|
||||
#define BLOCK_SIZE (10*1024)
|
||||
|
||||
struct FMemArena::Block
|
||||
{
|
||||
Block *NextBlock;
|
||||
|
|
@ -74,10 +72,11 @@ static inline void *RoundPointer(void *ptr)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
FMemArena::FMemArena()
|
||||
FMemArena::FMemArena(int bs)
|
||||
{
|
||||
TopBlock = NULL;
|
||||
FreeBlocks = NULL;
|
||||
BlockSize = bs;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
@ -191,14 +190,14 @@ FMemArena::Block *FMemArena::AddBlock(size_t size)
|
|||
if (mem == NULL)
|
||||
{
|
||||
// Allocate a new block
|
||||
if (size < BLOCK_SIZE)
|
||||
if (size < BlockSize)
|
||||
{
|
||||
size = BLOCK_SIZE;
|
||||
size = BlockSize;
|
||||
}
|
||||
else
|
||||
{ // Stick some free space at the end so we can use this block for
|
||||
// other things.
|
||||
size += BLOCK_SIZE/2;
|
||||
size += BlockSize/2;
|
||||
}
|
||||
mem = (Block *)M_Malloc(size);
|
||||
mem->Limit = (BYTE *)mem + size;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue