Emulation of cache behavior. C++