Skip to content

Instantly share code, notes, and snippets.

@mfrandev
Last active June 26, 2025 22:00
Show Gist options
  • Save mfrandev/d3b83e5ebe911ef45235ac6165eb00bd to your computer and use it in GitHub Desktop.
Save mfrandev/d3b83e5ebe911ef45235ac6165eb00bd to your computer and use it in GitHub Desktop.
std::unordered_map default allocator
/**
* std::unordered_map uses the default allocator.
* Note: constexpr uint64_t MAP_SIZE = 1000000UL;
*/
void heapAlloc() {
std::unordered_map<uint64_t, MyClass> alloc;
for(uint64_t i = 0; i < MAP_SIZE; i++) {
alloc.emplace(i, MyClass(i, i+3));
}
for(uint64_t i = 0; i < MAP_SIZE; i++) {
alloc.erase(i);
alloc.emplace(i, MyClass(i, i+3));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment