You are here:

C/large array

Advertisement


Question
QUESTION: Hello.
I was wondering if you would be able to help me. I'm writing a C program that has to operate with a huge matrix that has dimensions of 2000 x 3000. When I declare this array (int myarray[2000][3000];) I get an error message that array is too large. What should I do? Is it possible to allocate more memory for my array. Unfortunately writing to/reading from file is not an option here because all the operations must take place in the memory (for acceptable speed). Thanks for your help. Sincerely, Tom.
ANSWER: Hi Tom

There is a solution to your problem you have to create the array dynamically using a pointer to a pointer variable and not calls to calloc or malloc can create your array, you have to create the same using farcalloc or farmalloc or by using the interrupt 0x67 for creating the same in the expanded memory.

regards
Joydeep

---------- FOLLOW-UP ----------

QUESTION:  Thank you very much for your answer. Unfortunately I did not fully understand it because I am a beginner. Would you be kind enough to send me a short example of how that's done. Thankfully, Tom

Answer
Hi Tom

Basically malloc and calloc takes the variable as unsigned int thats the reason they fail to allocate memory for over 64K where as farmalloc takes it as unsigned long try this for int array

int far *ptr;
if(ptr = (int far *)farmalloc(row*col*sizeof(int)))
  printf("Memory Allocation Successful");
/*Use your operation here*/
farfree(ptr);

check this out and if you like you can check this site and can join too its my personal website http://www.scodz.com mainly on C and C++ Programming.

Please feel free to ask in case if you find any difficulty.

regards
Joydeep

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Joydeep Bhattacharya

Expertise

Ability to solve C and Data Structure problems and puzzles with simple and easy to understand logic.

Experience

C, C++, Java, Data Structure, PHP, Web Designing

Organizations
http://www.scodz.com Designation: webmaster

Publications
http://www.scodz.com

Education/Credentials
Master of Computer Applications

Past/Present Clients
http://analysingc.50webs.com http://www.funforu.com

©2012 About.com, a part of The New York Times Company. All rights reserved.