Large 2D Array Problem

A

Adam Hartshorne

Hi,

I have the following problem, I have used the boost library (
boost::multi_array<float,2>) of size X by X. I initialise this using the
following line

typedef boost::multi_array<float, 2> array_type;
array_type D(boost::extents[num_vertices][num_vertices]);

This works fine up to a size of 5000 x 5000 then my program crashes at
the definition stage due to memory requirements. I am assuming the
boost::extents call stops my program creating a multi array of a size
bigger than 5000 x 5000. However in certain situations I need a bigger
2D array, any thoughts on how I can achieve this?

Adam
 
A

Alf P. Steinbach

* Adam Hartshorne:
Hi,

I have the following problem, I have used the boost library (
boost::multi_array<float,2>) of size X by X. I initialise this using the
following line

typedef boost::multi_array<float, 2> array_type;
array_type D(boost::extents[num_vertices][num_vertices]);

This works fine up to a size of 5000 x 5000 then my program crashes at
the definition stage due to memory requirements. I am assuming the
boost::extents call stops my program creating a multi array of a size
bigger than 5000 x 5000. However in certain situations I need a bigger
2D array, any thoughts on how I can achieve this?

You are probably allocating the array as a local variable.

That's 25 million floats, probably 100 million bytes, locally.

First, think about whether you really need an array that large, or at
all. It is typical for this question that the array isn't actually
needed. If, against expectation, it turns out to be needed, try to
allocate the array dynamically instead, using 'new', and keep in mind
how much memory you have, and that it's just a very very short step to
the case where instead you should be dealing with disk storage.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top