Open DanielSeemaier opened 1 year ago
Currently, there is no way to do that and to be fair it is not quite simple to do that. Currently whenever an element is removed it is replaced with a tombstone, thus, it's memory is never actually reclaimed. An operation like you describe would have to involve all threads acknowledging that previous values are gone. Thus, no thread can be in the process of completing previous queries. This kind of synchronisation is currently not supported by the interface. The only similar thing I could think of is implementing a new kind of migration technique, that basically forgets elements during the migration.
At the moment, I don't really see implementing something like this. But if you have an idea that could lead to a simpler solution, that is also not that difficult to implement I might be open to persuasion. Another technique might be using the range iterator interface to erase each element. However as I described before, this would not reclaim used memory.
Thanks for the reply! I was able to change my code so that I didn't need it anymore
An operation like you describe would have to involve all threads acknowledging that previous values are gone. Thus, no thread can be in the process of completing previous queries.
Just to make sure: it would have been fine if the clear-all operation wasn't thread safe; I basically just wanted to throw away the old hash map and get a new one with >= the old initial storage, but without paying for the allocation.
Is there a fast way to delete all elements of a growable or non-growable hash map without freeing its memory?