Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

multi dimension array in c++

Status
Not open for further replies.

boy

Advanced Member level 1
Advanced Member level 1
Joined
Sep 30, 2002
Messages
481
Helped
98
Reputation
196
Reaction score
58
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
 

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.
 

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!
:?
 

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.
 

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.
 

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}
 

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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top