@safe @nogc memory allocation

Dicebot via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed May 28 16:57:39 PDT 2014


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 write and use such a wrapper for 
> malloc?
>
> /Per

I don't know. 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.


More information about the Digitalmars-d-learn mailing list