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 26th, 2003, 08:07 AM
dryder3 dryder3 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 2 dryder3 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
can i declare a variable -> array[256][1024]?

I want to declare an multidimensional array as follows:

array[256][1024]....
but the program seems to crash.

when i use smaller numbers like
array[50][50]

the program runs like its supposed to..

can i use 256 and 1024?

Reply With Quote
  #2  
Old June 26th, 2003, 01:48 PM
ojibweindian ojibweindian is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 1 ojibweindian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
What type is the array?

What is the size of each element in the array?

Reply With Quote
  #3  
Old June 28th, 2003, 09:50 AM
Jason Doucette's Avatar
Jason Doucette Jason Doucette is offline
jasondoucette.com
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Canada
Posts: 378 Jason Doucette User rank is Private First Class (20 - 50 Reputation Level)Jason Doucette User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 h 23 m 8 sec
Reputation Power: 6
Are you declaring it inside of a function? If so, you are restricted to the stack size. Also remember that int main() is a function, as well! Take at look at this thread, in which we discussed all of this before.

Reply With Quote
  #4  
Old June 29th, 2003, 12:54 AM
bes bes is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 13 bes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
i got it up to 500...here is the code:

#include <iostream.h>
int main()
{
int theArray[500][500] = { {0,0}, {1,2}, {2,4}, {3,6}, {4,8}};
for (int i = 0; i<500; i++)
for (int j=0; j<500; j++)
{
cout << "theArray[" << i << "][" << j << "]: ";
cout << theArray[i][j]<< endl;
}
return 0;
}

Reply With Quote
  #5  
Old June 30th, 2003, 07:51 AM
mathurnitin mathurnitin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Bangalore, India
Posts: 13 mathurnitin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 m 10 sec
Reputation Power: 0
Send a message via Yahoo to mathurnitin
The program crashes because it exceeds the size of memory heap.
When you declare a multidmensional array, the program reserves some space. When the size of array is large enough, it runs out of space and hence gives an error.

Reply With Quote
  #6  
Old June 30th, 2003, 08:42 AM
Jason Doucette's Avatar
Jason Doucette Jason Doucette is offline
jasondoucette.com
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Canada
Posts: 378 Jason Doucette User rank is Private First Class (20 - 50 Reputation Level)Jason Doucette User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 h 23 m 8 sec
Reputation Power: 6
bes, you are delcaring it inside of a function (main() is a function, too). Declare it outside the function, as a global variable, and you will not be restricted by the stack space, which is normally 256 Kb (even though it sounds like its 1,024 Kb in your case - it can be changed with compiler settings). The global heap space is limited to 256 Mb for older 32-bit OS's, and limted only to 4 Gb for newer 32-bit OS's. Take a look at my first post above.

Reply With Quote
  #7  
Old June 30th, 2003, 03:04 PM
bes bes is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 13 bes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
lol..sorry im new at this stuff...I just got that outta my C++ book

Reply With Quote
  #8  
Old July 1st, 2003, 09:41 AM
Jason Doucette's Avatar
Jason Doucette Jason Doucette is offline
jasondoucette.com
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Canada
Posts: 378 Jason Doucette User rank is Private First Class (20 - 50 Reputation Level)Jason Doucette User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 h 23 m 8 sec
Reputation Power: 6
There is no need to be sorry... I just want to make it clear to everyone that there is a difference between declaring a variable inside of the main() function, and declaring it globally, outside of the main() function. This is a problem that caught me off guard, as well, so I know it will catch a lot of other people... I guess it is easy to think that you are not declaring variables on the stack when you declare them at will anywhere inside of main(), because it just does not seem like a function for some reason.

I should also note that dynamically allocating the arrays at run-time is another method of using all possible RAM with no complaints from the compiler.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > can i declare a variable -> array[256][1024]?


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 1 hosted by Hostway