🔒 Locked
memory-saving techniques
Advertisement
Original Post
- 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 ]
- 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 ]
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]
Read about my game, project #1
John 3:16
[edited by - d000hg on July 21, 2002 12:14:05 PM]
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]
-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]
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).
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
Steve
DirectX Programmer
Soon to be the new Bill Gates
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.
Now, when you''re talking about the SHORT (and releated) typedef in the Windows API, then the size is guaranteed to ensure backward compatibility.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement