@safe @nogc memory allocation
monarch_dodra via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed May 28 12:53:45 PDT 2014
On Wednesday, 28 May 2014 at 19:43:53 UTC, Nordlöw wrote:
> I would like my radix sort function radixSortImpl() at
>
> https://github.com/nordlow/justd/blob/master/intsort.d
>
> to not use the GC. However, when I tag with @nogc I get the
> error:
>
> intsort.d(195,47): Error: @nogc function
> 'isort.radixSortImpl!(byte[], "a", false).radixSortImpl' cannot
> call non- at nogc function 'std.array.uninitializedArray!(byte[],
> immutable(ulong)).uninitializedArray'
>
> Is there an alternative to
>
> std.array: uninitializedArray
> Elem[] y = uninitializedArray!(Elem[])(n);
>
> that neither use the GC and nor preinitialize the data?
malloc? There's no wrapper around it though, like there is for
uninitializedArray.
Keep in mind though that currently, you have to choose either of
"pure" (GC) or "nogc" (malloc) if you need dynamic allocation :/
> Could the recent DMD pull optimization to scope here
>
> https://github.com/D-Programming-Language/dmd/commit/abc7033bf9cf7f7224a47e45096efc48a21b5ab8
>
> be used?
>
> /Per
I don't think scope can be used to create a dynamic array on the
stack. I think it requires the object's type be statically known.
I could be wrong though.
If you know "n" has a max size, you could you create a fixed size
array, or attempt a "alloca" array?
More information about the Digitalmars-d-learn
mailing list