CFanatic

Go Back   CFanatic > Programming > C Programming

help me in a big C program topic posted under C Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 05-31-2010, 09:09 PM
Member
 
Join Date: Feb 2010
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
techme is on a distinguished road
| More
Thumbs down help me in a big C program

Hi friends i wrote a C program for solving Poisson equation over a square plate.Where we have to define the grid size.i have defined several 2-d arrays in program to store the values. the problem size is quite big so i have to define the size of array
of order of 10000x10000...
but when i compile the program. it shows some error. how can i use such big arrays without much trouble.
Reply With Quote
  #2  
Old 05-31-2010, 09:12 PM
Member
 
Join Date: Feb 2010
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
creative is on a distinguished road
| More
Re: help me in a big C program

hey buddy!
don't try to declare this type...
your compiler will show errors...
Reply With Quote
  #3  
Old 05-31-2010, 09:16 PM
Senior Member
 
Join Date: Feb 2010
Posts: 102
Thanks: 0
Thanked 0 Times in 0 Posts
meyup is on a distinguished road
| More
Re: help me in a big C program

The size of each integer is 4bytes under windows and the C Compiler generally allocates memory in RAM. So , for now ur allocated memory is 40,00000 bytes and you do not have that much size of RAM installed in ur CPU. As a result , ur PC show error or does not responds.
Reply With Quote
  #4  
Old 05-31-2010, 09:17 PM
Member
 
Join Date: Feb 2010
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
creative is on a distinguished road
| More
Re: help me in a big C program

using tc its 2bytes for integers and in gcc its 4 bytes but it would be better if you use dynamic allocation for doing it so.
Reply With Quote
  #5  
Old 05-31-2010, 09:20 PM
Member
 
Join Date: Feb 2010
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
inspiration is on a distinguished road
| More
Re: help me in a big C program

I would rather go with a dynamically allocated array, that is, instead of

double array[MAX][MAX];

do something like
Code:
double *array[MAX];
int i;
for(i = 0; i < MAX; i++) {
array[i] = (double*) malloc(MAX * sizeof(double));
/* Insert here some check if the malloc went OK, be prepared for an IMPROBABLE out of memory situation */
}
Now you can use array[i][j] exactly the same way as before, it just works a bit different way internally: the program looks at array[i], which is a pointer on double, so it can be used as an array of doubles, and then addresses the j-th element thereof.

You must not forget to deallocate all this memory at the end of your program, though:

Code:
for(i = 0; i < MAX; i++) {
free(array[i]);
}
Hope this helps! [If not, you can try copying the error message here so that we can tell how to fix it.]

PS: You should not be limited by your computer memory too much. A 10000 x 10000 array of doubles still takes less than 1 GB. And virtually every computer nowadays uses virtual memory which is swapped on your hard drive. Rest assured that many other programs use MUCH more memory and work well.
Reply With Quote
Reply

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sin X C Program techme C Programming 6 08-12-2011 09:50 AM
Errors in Program inspiration C Programming 3 03-26-2010 09:02 PM
How to use iostat in c++ program. mathueie C++ Programming 0 05-04-2009 09:28 AM
Same program different O/P... !!! batman.pratik C Programming 5 10-21-2008 12:18 PM
Help with program using classes chaching C++ Programming 0 09-30-2006 05:52 AM



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.