-working betterC
This commit is contained in:
parent
cde772c077
commit
d8b01ee097
2 changed files with 19 additions and 45 deletions
|
|
@ -16,17 +16,6 @@ version (Windows)
|
|||
/*extern(Windows) void* __alloca(size_t size) @nogc nothrow @system;
|
||||
alias alloca = __alloca;*/
|
||||
|
||||
private const uint max_alloca = 10000;
|
||||
private char[max_alloca] alloca_array;
|
||||
private uint alloca_pos = 0;
|
||||
void* alloca(size_t length) @nogc nothrow
|
||||
{
|
||||
if(alloca_pos + length > max_alloca)alloca_pos = 0;
|
||||
void* ret = &alloca_array[alloca_pos];
|
||||
alloca_pos += length;
|
||||
return ret;
|
||||
}
|
||||
|
||||
extern(Windows) void ___chkstk_ms() @nogc nothrow @system;
|
||||
|
||||
extern(Windows) void __chkstk()
|
||||
|
|
@ -34,34 +23,35 @@ version (Windows)
|
|||
___chkstk_ms();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
private const uint max_alloca = 10000;
|
||||
private char[max_alloca] alloca_array;
|
||||
private uint alloca_pos = 0;
|
||||
void* alloca(size_t length) @nogc nothrow
|
||||
{
|
||||
if(alloca_pos + length > max_alloca)alloca_pos = 0;
|
||||
void* ret = &alloca_array[alloca_pos];
|
||||
alloca_pos += length;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
else version (Posix)
|
||||
{
|
||||
import core.sys.posix.pthread;
|
||||
import core.sys.posix.stdlib;
|
||||
public import core.stdc.stdlib : alloca;
|
||||
}
|
||||
|
||||
version(D_betterC)
|
||||
{
|
||||
private const uint max_alloca = 10000;
|
||||
private char[max_alloca] alloca_array;
|
||||
private uint alloca_pos = 0;
|
||||
void* alloca(size_t length) @nogc nothrow
|
||||
{
|
||||
if(alloca_pos + length > max_alloca)alloca_pos = 0;
|
||||
void* ret = &alloca_array[alloca_pos];
|
||||
alloca_pos += length;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
else public import core.stdc.stdlib : alloca;
|
||||
|
||||
static struct Mallocator
|
||||
{
|
||||
static T[] makeArray(T)(size_t length) nothrow @nogc
|
||||
{
|
||||
T[] ret = (cast(T*)malloc(T.sizeof * length))[0 .. length];
|
||||
|
||||
/*static if(__traits(isPOD, T))
|
||||
static if(__traits(isPOD, T))
|
||||
{
|
||||
static immutable T init = T.init;
|
||||
|
||||
|
|
@ -71,21 +61,13 @@ static struct Mallocator
|
|||
}
|
||||
}
|
||||
else
|
||||
{*/
|
||||
{
|
||||
static import std.conv;
|
||||
foreach(i;0..ret.length)
|
||||
{
|
||||
std.conv.emplace(&ret[i]);
|
||||
}
|
||||
// }
|
||||
|
||||
//static if(is(T == struct))std.conv.emplace(ret);
|
||||
//static import std.conv;
|
||||
//emplace
|
||||
/*foreach(i;0..ret.length)
|
||||
{
|
||||
memcpy(ret);
|
||||
}*/
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -94,7 +76,6 @@ static struct Mallocator
|
|||
T[] ret = (cast(T*)malloc(T.sizeof * length))[0 .. length];
|
||||
foreach(ref v; ret)v = initializer;
|
||||
return ret;
|
||||
//return (cast(T*)ret)[0 .. length];
|
||||
}
|
||||
|
||||
static T[] expandArray(T)(T[] array, size_t length) nothrow @nogc
|
||||
|
|
@ -107,17 +88,12 @@ static struct Mallocator
|
|||
{
|
||||
T[] ret = (cast(T*)malloc(T.sizeof * array.length))[0 .. array.length];//Mallocator.makeArray!(T)(array.length);
|
||||
foreach(i, ref v;ret)v = array[i];
|
||||
//ret[0 .. $] = array;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static T* make(T, Args...)(Args args)
|
||||
{
|
||||
T* ret = cast(T*)malloc(T.sizeof);
|
||||
//*ret = T.init;
|
||||
//static immutable T init = T();
|
||||
//memcpy(ret, &init, T.sizeof);
|
||||
//static if(__traits(hasMember, T, "__ctor"))ret.__ctor(args);
|
||||
static import std.conv;
|
||||
static if(__traits(isPOD, T))
|
||||
{
|
||||
|
|
@ -125,7 +101,6 @@ static struct Mallocator
|
|||
memcpy(ret, &init, T.sizeof);
|
||||
}
|
||||
else static if(is(T == struct))std.conv.emplace(ret, args);
|
||||
//else std.conv.emplace(ret, args);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -135,7 +110,6 @@ static struct Mallocator
|
|||
version(Posix)posix_memalign(&ret, alignment, length);//ret = aligned_alloc(alignment, length);
|
||||
else version(Windows)ret = _aligned_malloc(length, alignment);
|
||||
else static assert(0, "Unimplemented platform!");
|
||||
//posix_memalign(&ret, alignment, length);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue