Just so as not to invent hot water, I ask here ...
I have an application with a lot of arrays and it runs out of memory.
So the idea is to compress the List<int> to something else that will have the same interface (e.g. IList<T> ), but instead of int I could use short integers.
For example, if my range of values is 0 - 100,000,000, I only need ln2 (1,000,000) = 20 bits. Therefore, instead of storing 32 bits, I can trim the excess and reduce memory requirements by 12/32 = 37.5%.
Do you know about the implementation of such an array. C ++ and java would be fine too, as I could easily convert them to C #.
Additional requirements (as everyone starts to get from the idea):
- integers in ARE unique list
- they do not have a special property, so they are not compressed in any other way, and then reduce the number of bits
- If the range of values is one million, for example, lists will have from 2 to 1000 elements in size, but there will be many, so BitSets
- the new data container should behave like an overridable array (relative to the O () method)
EDIT:
Please do not tell me DO NOT do this. The requirement for this is well thought out, and this is the only option that remains.
In addition, a 1M range of values and 20 bits for it is ONLY EXAMPLE. I have cases with all the different ranges and whole sizes.
In addition, I could have even shorter integers, for example 7 bit integers, then the packaging would be
00000001 11111122 22222333 33334444 444.....
for the first 4 items packed in 5 bytes.
Almost finished coding it - will be published soon ...