PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > How to define and use large dynamic two dimension arrays
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
How to define and use large dynamic two dimension arrays

Réponse
 
LinkBack Outils de la discussion
Vieux 09/06/2008, 08h23   #1
Atemporal
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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.
  Réponse avec citation
Vieux 09/06/2008, 10h14   #2
Lionel B
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to define and use large dynamic two dimension arrays

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
  Réponse avec citation
Vieux 09/06/2008, 12h52   #3
Gianni Mariani
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to define and use large dynamic two dimension arrays

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 - 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.
  Réponse avec citation
Vieux 09/06/2008, 13h24   #4
James Kanze
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to define and use large dynamic two dimension arrays

On Jun 9, 1:52 pm, Gianni Mariani <gi4nos...@mariani.ws> 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 - 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:james.kanze@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

  Réponse avec citation
Vieux 09/06/2008, 13h30   #5
Lionel B
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to define and use large dynamic two dimension arrays

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 - 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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h21.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12176 seconds with 13 queries