More Game Coding Tidbits and Style That Saved My Butt
Small Memory Allocations
One of the best reasons to extend the C runtime memory manager is to write a better system to manage small memory blocks. The memory managers supplied in the C runtime or MFC library are not meant for tiny allocations. You can prove it to yourself by allocating two integers and subtracting their memory addresses as shown here:
int *a = new int; int *b = new int; int delta1 = ((int)b - (int)a)- sizeof(int);
The wasted space for the C runtime library was 28 bytes for a release build and 60 bytes for the debug build under Visual Studio.NET. Even with the release build, an integer takes eight times as much memory space as it would if it weren't dynamically allocated.
|More to Come|
This is part 2 of a 3 part series. The final installment will appear next week.
About the Author
Mike McShaffry, a.k.a. "Mr. Mike," started programming games as soon as he could tap a keyboard. He signed up at the University of Houston, where he graduated five and one-half years later. Then, he entered the boot camp of the computer game industry: Origin Systems. He worked for Warren Spector and Richard Garriott, a.k.a. "Lord British," on many of their most popular games. In 1997, Mike formed his first company, Tornado Alley. He later took a steady gig at Glass Eye Entertainment, working for his friend Monty Kerr, where he produced Microsoft Casino.
About the BookGame Coding Complete, Second Edition
By Mike McShaffry
Paraglyph Press, copyright 2005, Game Coding Complete, 2nd Edition.
Reprinted with permission.
Page 4 of 4