@safe @nogc memory allocation
safety0ff via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed May 28 17:38:14 PDT 2014
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 comparing allocated immutable pointer
> identity, only pointed values) it should work fine. But I have
> never done it in my code and not aware of possible pitfalls.
You also have to make sure your calls to malloc wont be
considered strongly pure and memoized.
e.g.:
int* a = cast(int*)malloc(4); // 4 should be considered immutable
int* b = cast(int*)malloc(4);
// a == b if memoized
// a != b otherwise (unless out of memory)
Perhaps the wrapper function should take a pointer reference as a
parameter (note: not immutable,) this also means that it can use
type inference.
More information about the Digitalmars-d-learn
mailing list