problem with very large float array

Started by
25 comments, last by iMalc 19 years, 3 months ago
Quote:Original post by iMalc
Also the maths for the array size [1024 * 1024 * 392] may be done with shorts since they are all less than 32767, so the result would be, uh... zero? Try [1024L * 1024L * 392L].


Nope, they'll all be ints. Unless he's working on a 16 bit system, because, well, then he's got 16 bit ints. In that case, his array would turn out to be 0 indeed. But that'd cause a compile error, wouldn't it?
Advertisement
pointer["every integer type you want"]

(ULONG)1024*1024*392 = 411041792 = 0x18800000 < 0xffffffff (MAX_LONG = ~0)

This is not a problem (you could use also signed (long) integers).

Also 16bit systems are able to address 64K!!!
I didn't write the old code, and it was quite a mess when i firt got it. It's my first contracting job, so it has been interesting. The reconstruction can use less memory, so it currently works, but it could run faster if i could create this array all at once, rather than having to do the calculations in sections. I think i will just stick with it doing it in two sections, to decrease the memory usage. Also, i could not use bits for the data, because the images are grayscale, not just 1 or 0.
Why don't you just make an array out of [392] pointers to arrays of [1024]*[1024]?
Quote:Original post by corrington_j
...
Also, i could not use bits for the data, because the images are grayscale, not just 1 or 0.


Why you use floats? Use unsigned char!
well the existing code i am working with uses this enormous array to do calculations, so that would be a lot of work to change to unsigned chars.
Quote:Original post by MaulingMonkey
Quote:Original post by iMalc
Also the maths for the array size [1024 * 1024 * 392] may be done with shorts since they are all less than 32767, so the result would be, uh... zero? Try [1024L * 1024L * 392L].


Nope, they'll all be ints. Unless he's working on a 16 bit system, because, well, then he's got 16 bit ints. In that case, his array would turn out to be 0 indeed. But that'd cause a compile error, wouldn't it?
Ah yes I remember now, I was using a 16-bit compiler when I had that problem.


corrington_j: It is easy to store the floats from zero to one as 1 byte instead of four. First make a small lookup table like this (for speed):
float lookupTable[256];void initLookupTable() //called once from your initialisation code{  for (int i=0; i<256; ++i)    lookupTable = i / 255.0f;}// then replace your array accesses...val = slices[j][k];//with...val = GetVal(i, j, k);//Where GetVal is defined as...float GetVal(int i, int j, int k){  return lookupTable[ slices[j][k] ];}//and the corresponding SetVal...void SetVal(int i, int j, int k, float newVal){  slices[j][k] = static_cast<unsigned char>(newVal*255.0);}//instead of...slices[j][k] = val;//use...SetVal(i, j, k, val);
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms

This topic is closed to new replies.

Advertisement