Standard allocators can optionally take a hint as a second parameter https://en.cppreference.com/w/cpp/memory/allocator/allocate
T* allocate( std::size_t n, const void * hint);
Leaving aside that this is formally deprecated in C++20 (which apparently doesn't mean that an allocator cannot have the hint argument):
Do you know of good uses of the hint
in standard or non-standard allocator implementations in existing code or theoretical code? Or is it a plain historical relic?
For context, I am trying to understand if the current hint can help with allocating when you have more than one device (e.g. GPU).
Note 1:
I am not asking how to allocate memory in CPUs or GPUs;
I am trying to see good or proven code that uses this hint
parameter internally, presumably for efficiency and particular types of memory.
Even if it is some exotic system.
Note 2: I am not asking how/if/what to pass as an argument of hint (i.e., "just pass the current pointer of your container"), like in the linked question. I am asking from the point of view of someone implementing a custom allocator.
std::allocator::allocate()
hint overload was removed but cppreference said it was used to hint a nearby memory location so maybe it was used for caching performance or in embedded systems/memory constrained contexts when you want to localize memory allocations. – Throathint
parameter with some success to write a more locality aware allocator. Unfortunately, the source code seems to be lost. The paper is cited by a bunch of others, but I have not checked if they actually use it. Otherwise, I guess one could pass thehint
parameter tommap
(although e.g. this library does not do so). – Maddalena