C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 6th, 2003, 08:07 AM
zergec zergec is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 2 zergec User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question multi dimensional array, memory allocation

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..

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > multi dimensional array, memory allocation


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT