-block allocator now track allocated blocks and is able to free memory

-jobs data is now allocated in System struct
-written memory cleanup (AddressSanitizer don't show any leak)
This commit is contained in:
Mergul 2019-06-18 16:45:38 +02:00
parent 9824b587fb
commit 235bbb49f2
7 changed files with 214 additions and 41 deletions

View file

@ -154,6 +154,24 @@ begin:
add_mutex = Mallocator.instance.make!Mutex();
}
void deinitialize() @trusted @nogc
{
if(m_ids_array)Mallocator.instance.dispose(m_ids_array);
if(m_free_stack)Mallocator.instance.dispose(m_free_stack);
if(m_blocks)
{
foreach(ref block;m_blocks)
{
if(block.data)block.free();
}
Mallocator.instance.dispose(m_blocks);
}
if(add_mutex)
{
Mallocator.instance.dispose(cast(void*)add_mutex); //workaround for compiler bug
}
}
void optimize() nothrow @nogc
{
if(m_stack_top < -1)m_stack_top = -1;
@ -176,7 +194,7 @@ begin:
begin += 65536;
}
memcpy(cast(void*)m_ids_array.ptr + begin * Data.sizeof, m_blocks[m_blocks_count-1].data.ptr, (m_last_id - begin) * Data.sizeof);
foreach(block;m_blocks[1..m_blocks_count])block.free();
foreach(ref block;m_blocks[1..m_blocks_count])block.free();
m_blocks_count = 1;
}
}
@ -193,9 +211,10 @@ begin:
{
assert(data !is null);
Mallocator.instance.dispose(data);
data = null;
}
Data[] data; //65536
Data[] data = null; //65536
}
private static struct Data