Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

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 September 25th, 2003, 10:53 AM
Watever Watever is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Montreal, Canada
Posts: 486 Watever User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 20 sec
Reputation Power: 6
euhm.... memory usage minimum ?

I don't know if that is in the good place. Cause there is no General discussion or anything but.....

what do you think would take less memory usage ? a table with 2 dimension (either same or different variables doesn't matter) or 2 table of 1 dimension ?

I was just wondering that.

I know that computers of modern age are fast and can take a lot of things in memory, it's not like in the old times. But still I love to reduce speed and memory usage at it's maximum. So what do you guys think ?



(if it's in the wrong place, delete or move it please)
__________________

Reply With Quote
  #2  
Old September 26th, 2003, 02:12 AM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Click here for more information.
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,717 Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Days 12 h 42 m 30 sec
Reputation Power: 1179
Depends on how/what you use the arrays for. C programmers can relate to this example in particular. Consider an array of strings. In C, strings are considered as arrays of characters. So an array of strings is really an array of arrays of characters (i.e.) a 2 dimensional array. Let's say we want to store 10 strings in an array. Now, there are two ways to store such an array. The first method is to declare an array like this:

char array[10][200];

This will declare a square (or rectangular) array, where there are 10 elements, each of which can store up to 200 characters. The problem with this type of array is that there may be lots of bytes wasted, especially if each string is not 200 characters long.

Another way is to declare a ragged array. You would declare an array of 10 character pointers like this:

char *array[10];

Then, as you read each string, you'd allocate only enough memory to store each actual string. Then you'd assign each string array to an element of the array (something like this).
char *ptr;
ptr = strdup("small string");
array[0] = ptr;
ptr = strdup("This is a longer string");
array[1] = ptr;
ptr = strdup("This is an even longer string");
array[2] = ptr;
... and so on.

This ragged array is a little more complex, but is more efficient because each string (i.e.) char array is of a different length, thus you don't have extra wasted memory.

Now, if all elements were of equal length, then you could go with a simple rectangular array. However, if the elements are of varying length and you want to save a lot of memory, ragged arrays are probably the way to go.
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month

Reply With Quote
  #3  
Old September 29th, 2003, 09:43 AM
Watever Watever is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Montreal, Canada
Posts: 486 Watever User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 20 sec
Reputation Power: 6
Thank you for bringing me up to that !

I didn't tought of that and it's stupid I used that in the past when I was coding in C !
damn I am now too old should I say

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > euhm.... memory usage minimum ?


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 3 hosted by Hostway
Stay green...Green IT