This sample demonstrates numerous advanced C++ techniques
concerning memory management. The sample is composed of 7
units, which are described below:
Unit 1: This unit demonstrates how to properly allocate and
destroy arrays of C++ objects.
Unit 2: This unit demonstrates usage of the placement new
operator. This technique can be used for avoiding
unnecessary dynamic memory allocations and implementing
Unit 3: The unit demonstrates how to write operators
new/delete for a user class. This technique can be used in
conjunction with other optimization techniques such as:
- optimizing performance by eliminating bottlenecks
associated with dynamic memory allocations.
- implementing custom allocators for reference counting
Unit 4: This unit shows how to write a custom STL compatible
allocator. The code includes two PERFORMANCE WARNINGS that
are specific to VC++'s implementation of STL.
Unit 5: The unit demonstrates one of many numerous ways of
implementing reference counting. Here, we use a common base
class. You can also use a so-called in-band memory header
paired with an allocator.
Unit 6 : The unit demonstrates how the "smart pointer" idiom
can be used together with reference counting. Smart pointer
and reference counting seemed to be made for each other!
Unit 7: The unit demonstrates a simple allocator
implementation that allows for memory tracking. This
infrastructure can be extended to support memory management
in a large scale C++ framework via classes of allocators.
The basic idea is to introduce a user allocator (Base::Allocator)
that includes an API to install a user callback. Next, right
a class that provides the callback and tracks the memory.
This technique works well with approach from unit3, where
operator new/delete are implemented for the base class.
This sample has been developed as a supplementary
material for the "Math and Physics for game developers"
class at Guildhall SMU.
The sample demonstrates how to define two rigid body
equations that are integrated numerically using the Forward
Euler integration method (the simplest first-order numerical
integration method possible).
The two equations are named WRF and BRF. The WRF suffix
stands for "World Reference Frame". It indicates that the
orientation is integrated using the angular momentum vector
in the world reference frame. An alternative method is to
integrate the angular velocity vector in the BODY reference
frame (BRF). The key difference between the WRF and BRF
equations is the former integrates angular momentum in the
WORLD reference frame, while the latter integrates angular
velocity in the BODY reference frame.