Jump to content
  • Advertisement
Sign in to follow this  
corrington_j

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.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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!!!

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
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);


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!