3

Standard allocators can optionally hints as default parameters 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?

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 cpu or gpus, I am trying to see good or proven code that used this hint parameter internally, presumably efficiency and for particular types of memory. Even if it is some exotic system.

Note 2: I am not asking how/if/what to pass as 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.

alfC
  • 12,434
  • 4
  • 54
  • 98
  • 1
    why leaving aside that it is deprecated? If there were good use cases, it wouldnt be deprecated, no? – 463035818_is_not_a_number Mar 17 '21 at 09:16
  • 2
    Does this answer your question? [Does an allocation hint get used?](https://stackoverflow.com/questions/15380318/does-an-allocation-hint-get-used) – underscore_d Mar 17 '21 at 09:18
  • @underscore_d mmm, thanks for the link. the only concrete case is the first answer (colony). It seems that it used the hint of std allocator blindly and got better performance simply doing that. I am asking from the point of view of an implementor of an allocator (e.g. of special memory, for example shared memory, mapped memory or gpu). – alfC Mar 17 '21 at 09:28
  • @largest_prime_is_463035818 apparently for allocators, deprecation doesn’t mean that the feature is removed but that the feature is not required in order to be a standard-like allocator. For example, allocator traits will keep takin the hint. And ignore it if it can not be passed. https://en.cppreference.com/w/cpp/memory/allocator_traits/allocate – alfC Mar 17 '21 at 09:32
  • thanks now I understand. Seems like I just didnt get the meaning of "which apparently doesn't mean that an allocator cannot have the hint" – 463035818_is_not_a_number Mar 17 '21 at 09:33

0 Answers0