Void initialization
Steven Schveighoffer
schveiguy at yahoo.com
Mon Dec 19 10:11:30 PST 2011
On Mon, 19 Dec 2011 12:24:18 -0500, Bear <joanyleprince at yahoo.fr> wrote:
> gc.malloc actually returns void[]
http://www.d-programming-language.org/phobos/core_memory.html#malloc
Looks like void* to me...
Or is there another function I'm not aware of? I think it should be
GC.malloc, not gc.malloc, so maybe I'm missing something...
> Bearophile's suggestion seems to work though, but it doesn't seem to
> improve
> performance for some reason... I guess I'll have to find some other way
> to make my
> prog quicker.
Actually, an issue with bearophile's suggestion is that it allocates a
block marked as containing pointers. Such a block is bulk-initialized to
0.
Try this:
float[] f = (cast(float*)GC.malloc(x * TF.sizeof, GC.BlkAttr.NO_SCAN))[0
.. x];
This will leave the memory uninitialized.
And depending on the usage, this optimization may or may not make a huge
difference.
-Steve
More information about the Digitalmars-d-learn
mailing list