Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

multi dimension array in c++

Status
Not open for further replies.

boy

Advanced Member level 1
Joined
Sep 30, 2002
Messages
481
Helped
96
Reputation
192
Reaction score
55
Trophy points
1,308
Location
Thailand
Activity points
3,963
how can i have a big array like [1000][1000][1000] in c++, i use gcc, but i get run time error
 

Ace-X

Advanced Member level 2
Joined
Jan 25, 2002
Messages
529
Helped
41
Reputation
82
Reaction score
14
Trophy points
1,298
Location
Germany
Activity points
5,150
Did you define it as a local variable? :)
All local variables are placed in the stack, which size is not infinite!
Try to redefine it as a global variable, i.e. outside of any function.
Or better use dynamic memory allocation with operator "new" or function like old "malloc".

Ace-X.
 

btbass

Advanced Member level 5
Joined
Jul 20, 2001
Messages
1,897
Helped
438
Reputation
880
Reaction score
287
Trophy points
1,363
Location
Oberon
Activity points
12,861
That is a big array!
What is it an array of? If it is an array of int, 2 bytes per int, thats 1000 * 1000 * 1000 * 2 bytes of memory.
Does your machine have > 2Gig of ram?
Try a smaller array, if that works, the problem is size!
:?
 

Ace-X

Advanced Member level 2
Joined
Jan 25, 2002
Messages
529
Helped
41
Reputation
82
Reaction score
14
Trophy points
1,298
Location
Germany
Activity points
5,150
btbass said:
That is a big array!
What is it an array of? If it is an array of int, 2 bytes per int, thats 1000 * 1000 * 1000 * 2 bytes of memory.
Does your machine have > 2Gig of ram?
Try a smaller array, if that works, the problem is size!
:?
Why RAM? It is virtual memory! So, your data will reside not only in physical RAM, but also in the swap file on the disk. For example, my system has 512 Mbytes of physical RAM, but I can easy create data structures with the size of 1 Gbyte or more. The maximum size depends only on available space for the swap file and on the maximum address space for one process in the OS.

Ace-X.
 

H.Disk

Newbie level 6
Joined
Feb 21, 2002
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
8
As far as I remmeber max memory pool for single task is limited to 4 GB.
In gcc sizeof(int)=4 so Your array overloads that mem pool.
 

S

sick_man

Guest
some thoughts

too define an array

do like this



define variable_name[x][y][z]

then you have a class by possition in the three dimentional array

you can also define arrays

using c stuctures
like
x=1000
y=1000
z=1000
variable_name[x]
variable_name[y]
variable_name[z]

int p=3
p= (x+y+z) + (-x-y-z)



p is then an origin of xyz

or you can do it in bytes
these same maths can be used by
the guy looking for dsp for coding a mux
for stereo fm
if you read the maths are L&R = ( (L+R) - (R-L) )
1024 is a close derivative
so three time 1024
so too do this
you code the array in three 8 bit words
or ask fred
http://www.fredosaurus.com/notes-cpp/

look at texts arrays of arrays {multidimentional arrays}
 

tom324

Full Member level 1
Joined
Jun 26, 2001
Messages
98
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Location
Croatia
Activity points
672
boy said:
how can i have a big array like [1000][1000][1000] in c++, i use gcc, but i get run time error
1. Try redesign your algorithm so it does not use 2GB for an array of data.

2. Alternatively, you can place data array in a file and operate on it. It will be damn slow, but it will work (assuming that there is at least 2 GB of free space on HD).

Tom
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top