std::vector<std::valarray<uint32_t> >
may also be an alternative.
Assuming, that your console program will do some sort of calculation, the rather unknown std::valarray
will be a good companion.
Be aware of the risk, that user provided size values are likely to lead to a std::bad_alloc
exception, so you may put at least the allocations into a try/catch block.
Another solution would be to collect all user provided size values in a container and then instantiate another, single container for data:
//Disclaimer: below code has never been tested and is rather about how to do such stuff in general,
//regardless of the few bytes gained for sacrificing CPU cycles.
#include <vector>
#include <valarray>
#include <numeric>
#include <cassert>
#include <exception>
void app(void)
{
std::vector<size_t> sizes;
std::valarray<uint32_t> data;
try
{
//collect N user defined sub-vector size values in 'sizes'
//.
//.
//.
size_t totalNumberOfValues = std::accumulate(sizes.begin(),sizes.end(),0u);
data.resize(totalNumberOfValues);
}
catch(std::bad_alloc& e)
{
//handle error
}
//accessing the minor/sub-vectors using the size values requires accumulation of adjacent size values of preceding sub-vectors.
//of course, these offsets could also be pre-computed.
size_t subVectorIndex /*...*/; //needs to be checked!
assert(subVectorIndex < sizes.size());
size_t subVectorSize = sizes[subVectorIndex];
size_t subVectorOffset = std::accumulate(sizes.begin(),sizes.begin()+subVectorIndex,0u);
//do NOT reallocate 'data' while twiddling around with pointers!
uint32_t* subVectorData = &data[subVectorOffset];
//well, using neat stuff like std::slice, std::gslice etc. is up to you now ;-)
}