casting int[] to bool[]

Saaa empty at needmail.com
Thu Jan 29 10:57:05 PST 2009


>
> It's probably due to the absurd amount of memory allocation you're
> causing.  Each call to split() allocates an array (whose size is not
> known in advance, so it requires several appends), and each call to
> to!(int[]) allocates _another_ array.  That's 1.4 million arrays
> you're allocating, most of which are garbage, and each allocation can
> potentially trigger a GC cycle.
>
> It would be a lot more efficient if you just parsed out the line yourself.
>
> auto data = splitlines(read(`data\parsed.dat`).idup);
> auto dataIn = new bool[][](data.length, 3);
>
> foreach(i, line; data)
> {
>    dataIn[i][0] = line[14] == '1';
>    dataIn[i][1] = line[16] == '1';
>    dataIn[i][2] = line[18] == '1';
> }
>
> Now we perform only a few allocations, all of which are before the loop.

Yay massive speedup!! (~2 sec for the loop)
Is `bool = x == y` faster than `if ( x == y ) true else false` ?

For the 60 large boolean part I used a loop.
Not that I really need the extra speedup (if any) but how could I manually 
unroll that loop?
I know you can do things like that in D..

btw. side note: I love slices :D

 auto sliceIn = dataIn[0..300];
 auto sliceOut = dataOut[0..300];

 rndGen.seed(1);
 randomShuffle(sliceIn, rndGen);
 rndGen.seed(1);
 randomShuffle(sliceOut, rndGen);





More information about the Digitalmars-d-learn mailing list