-added more documentation
-remove update() function from entity -currently max supported components count is 64 per type
This commit is contained in:
parent
546b73c567
commit
845f468d59
10 changed files with 199 additions and 64 deletions
|
|
@ -1,23 +1,23 @@
|
|||
/************************************************************************************************************************
|
||||
*It's internal code.
|
||||
*
|
||||
*Module contain memory allocator.
|
||||
*/
|
||||
module ecs.block_allocator;
|
||||
|
||||
import ecs.manager;
|
||||
import ecs.std;
|
||||
|
||||
/************************************************************************************************************************
|
||||
*Allocator allocate large blocks and return smaller blocks. When there is no more blocks then next large block is allocated.
|
||||
*By default freeing memory only returns it to allocator. To free large memory chunks freeMemory function is used.
|
||||
*freeMemory function return to system memory even if chunk blocks wasn't freed.
|
||||
*/
|
||||
struct BlockAllocator
|
||||
{
|
||||
private uint block_size;
|
||||
private uint blocks_in_allocation;
|
||||
|
||||
struct BlockPointers
|
||||
{
|
||||
void*[32] blocks;
|
||||
uint numberof = 0;
|
||||
BlockPointers* next_pointers = null;
|
||||
}
|
||||
|
||||
void* next_block = null;
|
||||
BlockPointers* pointers = null;
|
||||
|
||||
/************************************************************************************************************************
|
||||
*Get new block. Allocator automatically allocate next memory chunk if needed.
|
||||
*/
|
||||
void* getBlock() nothrow @nogc
|
||||
{
|
||||
if (next_block is null)
|
||||
|
|
@ -27,13 +27,35 @@ struct BlockAllocator
|
|||
return ret;
|
||||
}
|
||||
|
||||
/************************************************************************************************************************
|
||||
*Return block to allocator for further use.
|
||||
*/
|
||||
void freeBlock(void* block) nothrow @nogc
|
||||
{
|
||||
*cast(void**)block = next_block;
|
||||
next_block = block;
|
||||
}
|
||||
|
||||
private void allocBlock() nothrow @nogc
|
||||
/************************************************************************************************************************
|
||||
*Free whole used memory. This function return to system all memory chunks even if not every black was freed.
|
||||
*/
|
||||
void freeMemory() nothrow @nogc
|
||||
{
|
||||
while(pointers)
|
||||
{
|
||||
foreach(i;0..pointers.numberof)
|
||||
{
|
||||
Mallocator.alignDispose(pointers.blocks[i]);
|
||||
}
|
||||
BlockPointers* next_pointers = pointers.next_pointers;
|
||||
Mallocator.dispose(pointers);
|
||||
pointers = next_pointers;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void allocBlock() nothrow @nogc
|
||||
{
|
||||
next_block = cast(void*) Mallocator.alignAlloc(
|
||||
block_size * blocks_in_allocation, block_size);
|
||||
|
|
@ -57,17 +79,16 @@ struct BlockAllocator
|
|||
*pointer = null;
|
||||
}
|
||||
|
||||
void freeMemory() nothrow @nogc
|
||||
struct BlockPointers
|
||||
{
|
||||
while(pointers)
|
||||
{
|
||||
foreach(i;0..pointers.numberof)
|
||||
{
|
||||
Mallocator.alignDispose(pointers.blocks[i]);
|
||||
}
|
||||
BlockPointers* next_pointers = pointers.next_pointers;
|
||||
Mallocator.dispose(pointers);
|
||||
pointers = next_pointers;
|
||||
}
|
||||
void*[32] blocks;
|
||||
uint numberof = 0;
|
||||
BlockPointers* next_pointers = null;
|
||||
}
|
||||
|
||||
uint block_size;
|
||||
uint blocks_in_allocation;
|
||||
|
||||
void* next_block = null;
|
||||
BlockPointers* pointers = null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue