Quantcast

Maximum PC

It is currently Fri Jul 25, 2014 5:45 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Question about arrays in C++
PostPosted: Sat Feb 14, 2009 2:02 pm 
Team Member Top 500
Team Member Top 500
User avatar

Joined: Mon Jan 08, 2007 1:41 pm
Posts: 2033
I'm currently working on a fairly large program (large to me, about 1k lines :wink: ) that utilizes more than a few multi-dimensional arrays. I'm trying to be mindful of how much memory my program consumes and how efficient it is.

Here's one array:
Code:
int data[82][10];


820 integers... about 3MB. I guess that's not "bad" per se, but the only numbers ever stored in this array are all <10 and >=0. You can see how this might bug me--all those extra bytes are used for nothing.

My question is... is there some other data type that might better suit my purposes? I have no need for the two billion or so upper limit of the int data type. However, it remains that any data type used must be able to be typecasted into an int and vice versa.

It occurred to me that a char data type might be able to store my data more efficiently... but is that feasible? It's char after all and I want #s. With all the millions of data types in windows.h... you'd think there's something that would do the trick?


Top
  Profile  
 
 Post subject:
PostPosted: Sat Feb 14, 2009 6:24 pm 
Little Foot
Little Foot
User avatar

Joined: Mon Jul 28, 2008 1:39 pm
Posts: 123
well you can always use short. (Or char, that works too). I prefer short myself. That would about halve your memory usage.


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group