Make sure calculate_memory matches with the allocations. Fix some errant asserts.
Use the info structure to keep track of our memory block sizes to reduce duplicated code and cut down on errors.
Avoid repeated adds and ensure correct round-trip result.
These minor optimizations were probably already done by the compiler but they can't hurt.