1 module Dgame.Internal.m3;
2 
3 package(Dgame):
4 
5 @nogc
6 T make(T : U[], U)(size_t len) nothrow {
7     import core.stdc.stdlib : malloc;
8     
9     static assert(!is(U : V[], V), "Only basic types are allowed");
10 
11     void* p = malloc(len * T.sizeof);
12     return p ? (cast(U*) p)[0 .. len] : null;
13 }
14 
15 @nogc
16 T remake(T : U[], U)(ref T arr, size_t len) nothrow {
17     import core.stdc.stdlib : realloc;
18     
19     static assert(!is(U : V[], V), "Only basic types are allowed");
20 
21     immutable size_t new_len = len + arr.length;
22 
23     void* p = realloc(arr.ptr, new_len * T.sizeof);
24     return p ? (cast(U*) p)[0 .. new_len] : null;
25 }
26 
27 @nogc
28 void unmake(T : U[], U)(ref T arr) nothrow {
29     import core.stdc.stdlib : free;
30     
31     static assert(!is(U : V[], V), "Only basic types are allowed");
32 
33     free(arr.ptr);
34 }