Re: @safe @nogc memory allocation

2014-05-28 Thread safety0ff via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 23:57:40 UTC, Dicebot wrote: I believe within current language semantics even considering `new` pure is broken, there was a very recent thread discussing it in digitalmars.D group. If you can be sure that your code won't break basic sanity requirements (never co

Re: @safe @nogc memory allocation

2014-05-28 Thread Dicebot via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 21:31:41 UTC, Nordlöw wrote: It is also because `malloc` can return null when out of memory and `new` will throw an Error. Wrapper around `malloc` that throws `OutOfMemoryError` on null can be considered of same purity class as `new`. Does this mean that I should

Re: @safe @nogc memory allocation

2014-05-28 Thread Nordlöw
It is also because `malloc` can return null when out of memory and `new` will throw an Error. Wrapper around `malloc` that throws `OutOfMemoryError` on null can be considered of same purity class as `new`. Does this mean that I should write and use such a wrapper for malloc? /Per

Re: @safe @nogc memory allocation

2014-05-28 Thread Dicebot via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 21:09:26 UTC, bearophile wrote: Dicebot: It is also because `malloc` can return null when out of memory and `new` will throw an Error. Wrapper around `malloc` that throws `OutOfMemoryError` on null can be considered of same purity class as `new`. One wrapper sho

Re: @safe @nogc memory allocation

2014-05-28 Thread bearophile via Digitalmars-d-learn
Dicebot: It is also because `malloc` can return null when out of memory and `new` will throw an Error. Wrapper around `malloc` that throws `OutOfMemoryError` on null can be considered of same purity class as `new`. One wrapper should have a template argument to specify the type of the items

Re: @safe @nogc memory allocation

2014-05-28 Thread Dicebot via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 20:51:08 UTC, Nordlöw wrote: malloc? There's no wrapper around it though, like there is for uninitializedArray. Is the fact that malloc() can't be pure when new is a limitiation in the type system? Do we need a yet another code tag for this? /Per It is also be

Re: @safe @nogc memory allocation

2014-05-28 Thread Nordlöw
malloc? There's no wrapper around it though, like there is for uninitializedArray. Is the fact that malloc() can't be pure when new is a limitiation in the type system? Do we need a yet another code tag for this? /Per

Re: @safe @nogc memory allocation

2014-05-28 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 20:00:17 UTC, safety0ff wrote: I think malloc isn't @safe and alloca doesn't work if your function can throw. Yeah, uninitializedArray is also *only* trusted if the type in question has no indirections. I've heard of several bugs with alloca, but I don't know the

Re: @safe @nogc memory allocation

2014-05-28 Thread safety0ff via Digitalmars-d-learn
I think malloc isn't @safe and alloca doesn't work if your function can throw.

Re: @safe @nogc memory allocation

2014-05-28 Thread monarch_dodra via Digitalmars-d-learn
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.radixSor

@safe @nogc memory allocation

2014-05-28 Thread Nordlöw
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-@n