2 ms·
Copying large objects is significantly more expensive than copying small objects, and the cost is exacerbated due to cache effects. The C++ language contains a
by nneonneo 6y ago
Copying large objects is significantly more expensive than copying small objects, and the cost is exacerbated due to cache effects. The C++ language contains a lot of optimizations for trivially copyable objects, e.g. std::copy, so having a realloc optimization for vectors would seem to be natural.
glibc malloc switches to mmap for allocations above ~128KB by default, which could be reached by vectors with just a few thousand elements (or a few very large objects). glibc does use mremap to reallocate mmap’d chunks - so in that sense the memory remapping hacks are already present in a general purpose library.