How do i solve that !

Well here are the standard containers.
https://en.cppreference.com/w/cpp/container
Study them and see which you think is best.
Its just asking you what container wastes the least memory. You don't have to compress the data or do anything screwy here that you haven't covered.
to minimize memory requirement as much as possible


For these sort of tasks, std::vector would usually be the first choice. However, when an element is added that exceeds the current vector memory allocation, it will obtain more memory of a larger size and copy the existing elements to this new memory and then free the old memory. Hence for a short time during this re-allocation memory requirements will more than double. Hence to minimize memory requirement, in this case vector wouldn't be the choice.

Knowing how the data is to be accessed will then help with the choice - deque, list. There is also queue and stack if they are appropriate.
Then again, the std::list is a double-linked list. We thus know a minimum that it needs for each data element to be clearly more than what std::vector needs.
Yep. It depends upon what is being asked by 'minimize memory requirement'.
Indeed. Is it "when finished, occupy the least memory possible" or is it "while processing, occupy the least memory possible". Or perhaps both.
It's a ridiculous question to ask a beginner. First, you never have an unknown number of ints, and if you think you do, then you haven't studied the data close enough yet. There will be some maximum size that you're willing to deal with, a most-common size, and the solution for dealing with 1000 ints is different than the solution for dealing with gigabytes of ints. And it depends on what the values of these ints are. If 99% of the ints are 0, that's a different solution than if they're uniformly distributed to 2^32 or whatever.

A hybrid approach where you have a few chains of vectors may be a solution. But there isn't enough information to know.

Also, 1-poster with a likely commercial link in profile.
Last edited on
Also, 1-poster with a likely commercial link in profile.


aka a traffic generator.
and the original post has now been removed....
Topic archived. No new replies allowed.