# problem with very large float array

This topic is 5220 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Quote:
 Original post by iMalcAlso 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?

##### Share on other sites
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!!!

##### Share on other sites
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.

##### Share on other sites
Why don't you just make an array out of [392] pointers to arrays of [1024]*[1024]?

##### Share on other sites
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!

##### Share on other sites
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.

##### Share on other sites
Quote:
Original post by MaulingMonkey
Quote:
 Original post by iMalcAlso 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);

• 13
• 35
• 39
• 15