This is 8*50*400*200*200 = 6,4000,000,000 as I do the computation. You just asked for the
impossible: 6.4GB of data allocated in a 32-bit address space with an absolute maximum of
4.2GB.
Even if you use the value 5 instead of 50, that's 640MB. That's asking a lot. The issue
is not the total space available, but the total amount of contiguous space available. This
is a function of how your memory is fragmented by executable code, data segments, etc.
You should essentially not expect to get this much memory in a single chunk. Arrays of
arrays are a better approach (the example of nested std::vector, for example). because
each fragment might fit, where the entire array will not. NOTHING is going to allow you
to allocate this much memory on 32-bit windows. You can use memory-mapped files to window
into pieces of something this large, or you can use Win64 where you can have 8TB of
virtual memory. Note that you had better have about 10GB of swap file allocated, and I
suspect that the performance of working on an array this size will be dominated by page
fault time, and therefore execution will be unrealistically long if all you do is iterate
over the array.
joe
On Fri, 14 Oct 2005 12:42:39 +0100, "ma" <
ma@nowhere.com>wrote:
Quote
Thanks for your reply and sorry for lack of information:
The code that I have is something such as follow:
class myarray
{
private:
double * m_data;
public:
void init(int dim1,int dim2,int dim3,int dim4)
{
m_data= new double[dim1 * dim2 * dim3 * dim4]; // this is the place
that I get out of memory error
}
}
the call to function is as follow:
...
myarray anarray;
anarray.init(50,400,200,200);
...
I like to know how I can allocate a multidimensional array dynamically.
I need the array to do the following:
1- Read and write to array and pass it to different function. (One instance
of the array)
2- Writing to a file (another instance of the array)
3- Reading from a file (another instance of the file)
In some run of the application, the size of this array may increase to 1 or
2GByte. What is the real restriction on memory allocation?
Best regards
<adebaene@club-internet.fr>wrote in message
news:1129286605.605717.278550@g43g2000cwa.googlegroups.com...
>
>ma wrote:
>>Hello,
>>
>>In an application that I am developing I need a 4 dimensions
>>array (such a[5][400][200][200]). My PC has 2G Ram and running windows XP
>>professional.
>Are we speaking about chars (raw bytes), or something else?
>
>The quantity of RAM is (mostly) irrelevant to your problem....
>
>>Since this arrays should be a dynamic one ( the size of each dimension
>>could
>>be changed in run time), I tried to write a class to wrap it. In my
>>class I
>>tried to allocate a one dimension array and then intelligently selecting
>>the
>>best one. But I was unsuccessful. A search shows me that I can't do this
>>as:
>>
>>
>>
>>1- I can't allocate more than 32 MB at each time. ( is it a real
>>restriction?)
>Wrong. Where have you seen such a thing?
>>
>>2- I am getting out of memory when I am trying to allocate memory.
>Please shos some code that demonstrate how you are running out of
>memory...
>
>>
>>To solve the problem I am looking for help:
>>
>>1- Is there any tutorial or document on how to solve the problem?
>The question is not precise enough...
>
>>
>>2- Is there any a library or a class for multidimensional array
>>allocation.
>std::vector<std::vector<std::vector<std::vector>int>>>>is the
>easiest solution at hand, though it is a bit clumsy and is probably not
>optimum in memory usage.
>boost::multi_array may also be an option. But since we don't know
>anything about your problem (what is the use of this memory?), we can't
>really help.
>
>>3- Can I use a memory map file to solve the problem? Is it a good
>>idea?
>What problem? If your data are bytes, this means a 80 MB allocation.
>Except if you have a quite big application, this is not a problem per
>se.
>
>Arnaud
>MVP -VC
>
Joseph M. Newcomer [MVP]
email:
newcomer@flounder.com
Web:
www.flounder.com">
www.flounder.com
MVP Tips:
www.flounder.com/mvp_tips.htm">
www.flounder.com/mvp_tips.htm
-