using D without GC
Alex Parrill via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jun 7 18:55:57 PDT 2015
On Sunday, 7 June 2015 at 16:25:29 UTC, Oleg B wrote:
>
> auto myalloc(T)( size_t count )
> {
> struct Impl{ size_t len; void* ptr; }
> union Wrap { Impl impl; T[] arr; }
> auto ret = Wrap( Impl( count, calloc( count, T.sizeof ) )
> ).arr;
> enforce( ret.ptr !is null );
> return ret;
> }
>
Note that you can slice non-gc memory. `Impl` is basically what a
slice is internally.
auto ret = calloc(count, T.sizeof)[0..(count*T.sizeof)]
More information about the Digitalmars-d-learn
mailing list