Fixed issues and bugs
-moved system destroy functionality to System structure "destroy()" function -now arrays are properly destroyed (with destructor calling (__xdtor)) -fixed bug which makes BlockAllocator crashing after freeing it's memory -fixed many smaller memory leaks
This commit is contained in:
parent
74179b4fc8
commit
96bbcb9956
5 changed files with 87 additions and 39 deletions
|
|
@ -156,7 +156,7 @@ static struct Mallocator
|
|||
{
|
||||
T[] ret;
|
||||
|
||||
if(length > array.length)
|
||||
if (length > array.length)
|
||||
{
|
||||
ret = (cast(T*) realloc(array.ptr, T.sizeof * length))[0 .. length];
|
||||
static if (__traits(isPOD, T))
|
||||
|
|
@ -178,21 +178,25 @@ static struct Mallocator
|
|||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
static if (__traits(hasMember, T, "__xdtor"))
|
||||
{
|
||||
foreach (i; length .. array.length)
|
||||
{
|
||||
array[i].__xdtor();
|
||||
}
|
||||
}
|
||||
else static if (__traits(hasMember, T, "__dtor"))
|
||||
{
|
||||
foreach (i; length .. array.length)
|
||||
{
|
||||
array[i].__dtor();
|
||||
}
|
||||
}
|
||||
ret = (cast(T*) realloc(array.ptr, T.sizeof * length))[0 .. length];
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -297,13 +301,34 @@ static struct Mallocator
|
|||
return ret;
|
||||
}
|
||||
|
||||
static void dispose(T)(T object) nothrow @nogc
|
||||
static void dispose(T)(T object)
|
||||
{
|
||||
static if (__traits(hasMember, T, "__xdtor"))
|
||||
object.__xdtor();
|
||||
else static if (__traits(hasMember, T, "__dtor"))
|
||||
object.__dtor();
|
||||
free(cast(void*) object);
|
||||
static if (isArray!T)
|
||||
{
|
||||
alias TT = PointerTarget!(typeof(object.ptr));
|
||||
static if (!isPointer!TT)
|
||||
{
|
||||
static if (__traits(hasMember, TT, "__xdtor"))
|
||||
{
|
||||
foreach (ref TT t; object)
|
||||
t.__xdtor();
|
||||
}
|
||||
else static if (__traits(hasMember, TT, "__dtor"))
|
||||
{
|
||||
foreach (TT t; object)
|
||||
t.__dtor();
|
||||
}
|
||||
}
|
||||
free(cast(void*) object.ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
static if (__traits(hasMember, T, "__xdtor"))
|
||||
object.__xdtor();
|
||||
else static if (__traits(hasMember, T, "__dtor"))
|
||||
object.__dtor();
|
||||
free(cast(void*) object);
|
||||
}
|
||||
}
|
||||
|
||||
static void alignDispose(T)(T object)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue