473,395 Members | 1,688 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to define and use large dynamic two dimension arrays

hi, all, i got some problem when define and use large dynamic two
dimension arrays.
At first, i use vector<vector<double>p1, i have three such arrays
and each is around 10000*10000, the program compiles ok, however, when
it gets following error when running

Unhandled exception at 0x7c812aeb in Value.exe: Microsoft C++
exception: std::bad_alloc at memory location 0x0013f988..

Then I turn to use the "new" method like the follows,

double **Profit1;
double **Profit2;
double **qq;

Profit1 = new double*[n1+1];
Profit2 = new double*[n1+1];
qq = new double*[n1+1];

for(int i=0;i<=n1;i++)
{
std::cout << i << std::endl;
Profit1[i] = new double[n2+1];
Profit2[i] = new double[n2+1];
qq[i] = new double[n2+1];
}

I still get the similar error.
What shall I do?
As I'm a newbie, please answer my question in a little more details,
thanks a lot.
Jun 27 '08 #1
4 1870
On Mon, 09 Jun 2008 00:23:38 -0700, Atemporal wrote:
hi, all, i got some problem when define and use large dynamic two
dimension arrays.
At first, i use vector<vector<double>p1,
Sounds reasonable (it has to be `vector<vector<double', but I guess
you know that already).
i have three such arrays and
each is around 10000*10000, the program compiles ok, however, when it
gets following error when running

Unhandled exception at 0x7c812aeb in Value.exe: Microsoft C++ exception:
std::bad_alloc at memory location 0x0013f988..
Blimey, I'm not surprised. 10000 x 10000 doubles is ... how many Gb of
memory? Your memory allocation failed.
What shall I do?
Request less memory. We can't tell you how to do that, since we don't
know what problem you're trying to solve (and it would probably be OT
here anyway). If you figure out how to reduce the memory requirements of
your program and have any implementation queries by all means ask again
here.

Regards,

--
Lionel B
Jun 27 '08 #2
Atemporal wrote:
....
What shall I do?
As I'm a newbie, please answer my question in a little more details,
thanks a lot.
There is a template class that might help - see this:

http://groups.google.com/group/alt.c...n&dmode=source

You're allocating 400MB, make sure that's really what you want to do.
Jun 27 '08 #3
On Jun 9, 1:52 pm, Gianni Mariani <gi4nos...@mariani.wswrote:
Atemporal wrote:
...
What shall I do?
As I'm a newbie, please answer my question in a little more details,
thanks a lot.
There is a template class that might help - see this:
http://groups.google.com/group/alt.c...+/msg/08904bff...
I don't see anything there that would solve his problem: a
bad_alloc exception.
You're allocating 400MB, make sure that's really what you want to do.
He's allocating 800MB. Which still shouldn't be a problem on
most modern, general purpose machines. And he's doing it three
times, which starts becoming a problem on many of the smaller
machines. For starters, he should get a machine with something
like 4GB main memory. (I can allocate two such vector on my
old Sparc, with only 512MB, but it ends up thrashing so much
that the machine becomes unusable.)

Alternatively, it's not too difficult to design a matrix class
which uses disk storage. But making each access a disk access
isn't going to speed things up; most likely, if he cannot get
the more powerful machine, then he'll probably have to carefully
organize the process so he only works on part of the data at a
time, to avoid constantly reading and writing to disk.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jun 27 '08 #4
On Mon, 09 Jun 2008 11:52:52 +0000, Gianni Mariani wrote:
Atemporal wrote:
...
>What shall I do?
As I'm a newbie, please answer my question in a little more details,
thanks a lot.

There is a template class that might help - see this:

http://groups.google.com/group/alt.c...g.learn.c-c++/
msg/08904bffef6f4ac1?hl=en&dmode=source
>
You're allocating 400MB, make sure that's really what you want to do.
More than that, surely? If a double is 8 bytes then memory = (approx, at
least) 3 x 10000 x 10000 x 8 bytes = 2400 MB = 2.4 GB.

--
Lionel B
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: fivelitermustang | last post by:
Actually, how would I go about allocating a four-dimensional dynamic array? I only know how to make two dimensional dynamic arrays: double **v; v = new double*; for (int i=0; i<C; i++) { v =...
2
by: raxitsheth | last post by:
I am using array in my progrm... is there any tool /tips so that i can convert my program to Dynamic Array...so that I can Add more Element to Array.... Code is around 4000 line 'C' (not C++)...
2
by: Nathan Sokalski | last post by:
I have a multidimensional array declared as the following: Dim guesses(14, 5) As Integer I want to assign all values in a specific dimension to another array declared as follows:
4
by: Larry Charlton | last post by:
Is there a high performance way in .Net to dynamically build single dimension arrays when the number of elements in the array is unknown until after the array is built? (i.e. I only need the array...
29
by: Ancient_Hacker | last post by:
It sure would be nice if I could have a macro that add a level of indirection to its argument. So if I write: AddIndirection( X ) The macro AddIndirection will do: #define X (*X) ...
10
by: Zhou Yan | last post by:
I want to define a pointer to a multiple-subscripted array. For instance, I have an array defined as below( I have reduced the size of the array as well as the dimension, but I think it OK to ask...
24
by: VijaKhara | last post by:
hi all, i am trying to create a dynamic 2D array with size N x 3 (N will be put in as a parameter) using the following code: int **xyz; int i,N; N=30000; xyz=malloc(3*sizeof(int*));
1
by: Peterwkc | last post by:
Hello all expert, i have two program which make me desperate bu after i have noticed the forum, my future is become brightness back. By the way, my problem is like this i the first program was...
5
by: suresh | last post by:
Hi, How to define a two dimensional array where each row is of type vector<map<string,int>>? My idea is, if "x" is such a variable, x is a vector where each cell of the vector is a...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.