Last active
June 26, 2025 22:00
-
-
Save mfrandev/d3b83e5ebe911ef45235ac6165eb00bd to your computer and use it in GitHub Desktop.
std::unordered_map default allocator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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