What is the Correct way to Malloc in @nogc section?

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Feb 13 22:38:19 PST 2015


On Sat, 14 Feb 2015 00:57:33 +0000, weaselcat wrote:

> On Friday, 13 February 2015 at 22:55:27 UTC, anonymous wrote:
>> On Thursday, 12 February 2015 at 23:52:41 UTC, Foo wrote:
>>> This is something I've done recently.
>>> Would be glad if my code will help you: https://github.com/Dgame/m3
>>> Especially the m3.d module could be useful for you.
>>
>> /* Class and Struct */
>>
>> emplace: You can't assume zero-initialization for structs. destruct: Is
>> not memory-safe, and must not be marked @trusted.
>>
>> /* Array */
>>
>> make: You can't assume zero-initialization. T.sizeof is not the size of
>> an element.
>> reserve: Not safe (you're freeing the old memory), must not be
>> @trusted.
>> append: T.sizeof is not the size of an element. You're multiplying
>> twice with T.sizeof; in `append`, and also in `reserve`.
>> destruct: Not safe, must not be @trusted.
> 
> Low level memory management isn't easy.
> Bugs like these wouldn't exist if D had decent smart pointer
> implementations in its standard library. You seem knowledgeable enough,
> care to lend a hand? ; )

how "smart pointers" can help here? they don't magically hiding all the 
low-level mechanics.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150214/66e46113/attachment.sig>


More information about the Digitalmars-d-learn mailing list