I need to initialize a very large multidimensional std::array of data:
class Thing;
class World
{
public:
World() : space{nullptr} {};
~World() = default;
private:
static unsigned int const size = 1000;
std::array<std::array<std::array<std::unique_ptr<Thing>, size>, size>, size> space;
};
If you try to instantiate this, G++ 4.8.2 chokes: it consumes all the available memory and will not return. That is, the compiler hangs and I never get an executable. Why is this? Note that clang++ has no trouble.
Note: I fully realize that putting this much data on the stack can overflow it. What is the best way to initialize it on the heap? I think making space a reference (to allocated memory) would be the best way, but I can't figure the syntax out.
World world;you're consuming slightly more than1000^3 * sizeof(std::unique_ptr<>)bytes. on a 64 bit system that would be a minimum 7.629 GB. So yeah, I'd say you crossed a line on the automatic variable space limit. I am dying to know the problem this is intended to solve.std::arrayby initializing each element directly.