|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 |
|
![]() |
| Outils de la discussion | |
|
|