I think the answer depends on what you mean by โwalkthroughโ and what you are trying to accomplish. You say that you add only to the list: how often do you add? How fast will the list grow? What is the acceptable overhead for memory usage, as well as memory reallocation time?
In the worst case scenario, 50,000,000 32-bit numbers = 200 megabytes using the most efficient storage engine. Assuming that in the end you can use this at your worst, is it normal to use this memory all the time? Is this better than reallocating memory often? What is the distribution of typical usage patterns? You can always use int[] , which has been allocated for just 50 million.
As for the speed of access to your operations, nothing happens faster than repeating and adding to a previously allocated memory fragment.
From OP edit: A decent amount of these sets may appear in memory (~ 100).
Hey now. Do you need to store 100 sets from 1 to 50 million numbers in memory at once? I think the bitter method is the only possible way this could work.
It will be 600 megabytes. Minor, but if they are (usually) mostly empty, it seems unlikely that you will find a more efficient storage mechanism.
Now, if you do not use bits, but rather use constructs with dynamic size, and they can somehow take up less space, you are talking about a real ugly scenario of allocating / freeing memory / garbage.
Suppose you really need to do this, although I can only imagine why. Thus, your server received a ton of memory, just select as many of these 6 megabyte bits as you need and recycle them. Disposal and collection of garbage is no longer a problem. Yes, you use a ton of memory, but that seems inevitable.
Jamie Treworgy
source share