Skip to main content
gamedev.net
🔒 Locked

memory-saving techniques

Started by jgb_irish Jul 19, 2002 at 9:49 PM 9 replies 450+ views
Original Post
jgb_irish
jgb_irish
Hi. What are some memory-saving techniques for fitting a large video game into a fixed amount of memory? jgb_irish
Kylotan
Kylotan
- Free everything you don''t use. This may involve reloading it later.

- Pack your structs so that there is no padding. This can largely be done by careful ordering of the members, and completed by a compiler setting. The ordering is important for speed, though.

- Use unions to share memory space when you know that certain data members will never be used at the same time.

- Compress values down to smaller types where possible. ints can often become shorts or chars, and up to 8 bools can be combined into one char.

- Use data structures with less overhead. A linked list might carry something like 12 bytes of overhead for every element, whereas an array or vector might have none.

- Procedurally generate content rather than load in data. This goes for maps, textures, etc.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files ]
d000hg
d000hg
How do you get 8 bools into one byte? The win32 BOOL is a 32bit int, the MSVC++ docs say their special bool type takes up one byte.



Read about my game, project #1


John 3:16


[edited by - d000hg on July 21, 2002 12:14:05 PM]
d000hg
d000hg
short:
-32768 to 32767
OR
0 to 65535
Just to clear that up.



Read about my game, project #1



John 3:16

[edited by - d000hg on July 21, 2002 12:17:50 PM]
Michalson
Michalson
quote:
Original post by d000hg
How do you get 8 bools into one byte? The win32 BOOL is a 32bit int, the MSVC++ docs say their special bool type takes up one byte.



1 Byte has 8 bits (1s or 0s). You can use each of those bits to represent one true(1)/false(0) boolean value. The only downside with this method is the speed penalty (while a 32bit boolean wastes the most space, it is the fastest for a cpu that works with 32bit chunks).
merlin9x9
merlin9x9
Well, d000hg, to clear things up even further, there''s no guarantee that short is 16 bits.
Evil Bill
Evil Bill
quote:
Original post by merlin9x9
Well, d000hg, to clear things up even further, there''s no guarantee that short is 16 bits.


Yes there is Search for "short" on MSDN. The int data type isn''t guaranteed to be 32-bits - its platform dependent, but short is.

Steve
DirectX Programmer
Soon to be the new Bill Gates
Member of the Unban Mindwipe Society (UMWS)
merlin9x9
merlin9x9
MSDN is not the definitive source for information on C or C++. Try Bjarne''s book. If memory serves, he basically says that the only size guarantees are that sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long), and that char is the same size as the smallest addressable unit for the target platform.

Now, when you''re talking about the SHORT (and releated) typedef in the Windows API, then the size is guaranteed to ensure backward compatibility.
Evil Bill
Evil Bill
Ah, sorry, i stand corrected (Page 75)
quote:

sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long)




Steve
DirectX Programmer
Soon to be the new Bill Gates
Member of the Unban Mindwipe Society (UMWS)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.