On 12/19/2011 01:04 PM, Bear wrote:
Using D1, I have a program that creates tons of float[] ; for performance
reasons, I would like them to be uninitialized.
I've tried replacing
float[] f = new float[x];
by
float[] f = cast(float[])std.gc.malloc(x*4);
Unfortunately I keep running into "Access violation" and sometimes "Array
bounds error". I've tried adding
setTypeInfo(typeid(float), f.ptr);
and hasNoPointer(f.ptr);
which didn't work.
However
f[] = float.nan;
solved the problem, but kinda defeats the purpose of using malloc...
What am I doing wrong?
Are you using GDC?
https://bitbucket.org/goshawk/gdc/issue/287/casting-between-array-types-is-broken
If so, this is the workaround:
float[] f = (cast(float[])std.gc.malloc(x*4))[0..x];