improvements to C++ memory efficiency