|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi,
I have a problem which i don't know exactly what it is.. So the subject of the message is also abit confusing.. I describe a multidimensional (2D) array staticly. I have one of the dimensions large (~200 000) and the other is 3. It is for handling the 3D coordinates of a geometry. #define size 200 000 ... double marray[size][3]; ... but i have 10 of this dimensional arrays. During compilation there is no error but at runtime i get a segmentation error. ( And when i reduce the size to e.g. 60 000, it compiles and runs normally... Is there somehow limitations in C to describing the variables?? How should i handle this? Second thing is: In the same program i want to describe these multidimensional arrays dynamically with MALLOC. Since i don't want to copy and paste the same procedure for every array i want to write a function to do this. I wrote this function and call this function from the main function. But it does not work... i think i don't know how to send the **pointer to a function.. I fsomeone has exprience with it, can you please help me... #include<stdio.h> #include<math.h> #include<stdlib.h> main() { int size1=65000,size2=3; double **zer; createmarray(size1,size2,zer); /* * .. * do whatever i want..... * .... * */ freemarray(size1,size2,zer); return; } void createmarray(int size1, int size2, double **xyz) { int i; // index MALLOC(xyz, sizeof(double *) * size2); for (i = 0; i < size2; i++) { MALLOC(xyz[i], sizeof(double) * size1); } return; } void freemaray(int size1, int size2, double **xyz) { int i; // index for (i = 0; i < size2; i++) { free(xyz[i]); } free(xyz); return; } Thanks in advance.. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > multi dimensional array, memory allocation |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|