On Wednesday, 7 August 2013 at 18:56:40 UTC, Ali Çehreli wrote:

import core.memory;

void main()
{
    auto p = GC.malloc(42);
}

But question to others: I wouldn't want garbage filled memory, right? So I should consider GC.calloc first.

Ali

Depends on why you think garbage is a problem I guess.

If it is because of false pointers, yet you aren't storing any pointers, then simply allocate using GC.BlkAttr.NO_SCAN. Then, garbage won't be a problem.

Otherwise, yeah, calloc should do the trick. Unfortunatly, calloc doesn't return much other than a void*, so depending on what you are doing, a qalloc + memset might be better.

Also, keep in mind that 0-initialization is not T.init initialization. This means that calloc'ed memory is not "initialized" per say, it is just zero'ed memory. An emplace is necessary before attempting, say an assignment.

Reply via email to