Link to home
Start Free TrialLog in
Avatar of peiyoke
peiyoke

asked on

Array declaration

I have an array of float values which range from 0.00 to 16.00. What can I do to the elements so that the memory needed to store the elements is minimized?
ASKER CERTIFIED SOLUTION
Avatar of braveheart
braveheart

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ozo
also, are there correlations between values in the array?
do the values always increase as the array index increases?
do consecutive entries tend to have close values?
Avatar of peiyoke
peiyoke

ASKER

braveheart,
could you elaborate more on your key point?

ozo,
yes, there are correlations between values in the array. but it is not necessary that the values increases as the array index increases.

I think the key point is that we can take less memory to store the elements
if we know some limitations on what their values can be.
Do we?  What do we know about those limitations?
peiyoke, if you can't proceed with the help we have given you, you will have to provide us with more information about the data.

With what accuracy or precision do you have to store the data?
How many decimal places or significant figures?

Are there any other interesting features about the data?
You have already told us the upper and lower bounds but is there anything important about the distribution or ordering of the values?

For instance, it may be more space efficient to store not the actual numbers but the difference between one number and the previous one, or the difference between each number and the mean value.  Maybe the numbers are all multiples of some value or at least share some common factors.
Avatar of peiyoke

ASKER


I need to have the exact values in float data type for more accuracy. I can't use any other values to represent the array elements.  
Avatar of peiyoke

ASKER


The limitation on the array values is only the range from 0 to 16.
If that's all the restriction you can give, then all you can save is a few bits per entry.
Avatar of peiyoke

ASKER


ozo,

how can I save the few bits per entry? what should I do to the array elements? please give me some advice. Thank you!!
If you need the exact values, stored to the maximum precision that is permitted by the data type, and there is nothing remarkable about the data, what makes you think that you can compress the data?

Compression relies on the fact that the data are taking up more space than is necessary, either in each item of data, or in the distribution.
If you need to save the full precision of your floating point data type,
we'll need to know exactly what that format is.
Is it IEEE format?  How many bits?
We could save the sign bit, and the few bits it takes to represent larger mantisas, but that's about it.

(But are sure you really need the full precison over the full range?)
If your floating point format can't distinguish between
15.999999999999998 and
15.999999999999999
then is there any use in distinguishing between
0.000000000000000000001 and
0.000000000000000000002 ?
If you only need to keep the same absolute error as a 64 bit IEEE  float,
then you can reduce your storage from 64 bits to 53 bits.

Or if you can know that some values are more likely to appear than others,
(either globally, or in the context of knowing the values of nearby numbers in the array)
then we can allocate fewer bits to more likely values, and more bits to less likely values.
The better you can predict which values are most likely, the fewer bits we'd need to specify which value actually occured.
Avatar of peiyoke

ASKER

Actually what I have been doing is that I have a set of values ranging from 0 to 256. Then I reduced all the values to a range of 0 to 16 using uniform quantization. To store the set of unsigned char values, I need 8 bits. Now that I have reduced the values from 256 levels to 16 levels, I hope to store the values using 4 bits.  If I am not taking the integral part of the new values, what should I do to my values?


Experts, I am a very fresh student in programming and C language. Can both of you explain in a simpler way, please?  Thanks to both of you for the help.

Are these values in the range 0-256 i.e. integers, or are they 0.0-256.0, i.e. reals?

What is uniform quantization?

Why are you storing numerics as unsigned char?

You don't have to take the integral part of a value to store it as an integer.  If you are only interested in 2 decimal places, then multiply by 100 and store as an integer, for instance.

I don't know how to explain it any simpler.
If each element can have one of 256 distinct values, the easiest way to store them,
while minimizing the memory needed to store the elements, is in a char.
If there are only 16 different values that each element can take,
then you can store them in 4 bits each, (but you lose 4 bits of precision converting them, which you said you didn't want to do)
Avatar of peiyoke

ASKER

ozo,

one last question. how do I store the array elements in 4 bits(what data type is that)?
That would be packing two elements into a char.
or perhaps bit-field structure members.