2 ms·
Legacy code and development time. When I write C++ code that deals with large datasets, I try to avoid large continuous buffers as much as possible. For cache
by Const-me 9y ago
Legacy code and development time.
When I write C++ code that deals with large datasets, I try to avoid large continuous buffers as much as possible.
For cache locality, an aligned 1GB buffer is practically the same as a set of 64 aligned continuous buffers, 16MB/each. You’ll only hit RAM latency when crossing the boundary between the buffers, i.e. only 63 times through the whole 1GB of data.
One problem is std::vector. The standard says the whole vector must be continuous, i.e. to split large buffer into smaller chunks, one needs to implement a custom container on top of that.
Apparently, authors of C++ think the problem will go away by itself, with the switch to 64-bit platforms.
- DiThi 9y agoThe problem does go away because of how addressing works. If you read my other comment, the address is masked for fast and safe sandboxing. If you have a huge virtual address space, it's practically guaranteed you'll have a contiguous chunk even when the actual memory is very fragmented.