VowpalWabbit / vowpal_wabbit

Vowpal Wabbit is a machine learning system which pushes the frontier of machine learning with techniques such as online, hashing, allreduce, reductions, learning2search, active, and interactive learning.
https://vowpalwabbit.org
Other
8.49k stars 1.93k forks source link

Custom allocator for vw library #1987

Open rajan-chari opened 5 years ago

rajan-chari commented 5 years ago

Allow users of vw library to provide their own allocator.

jackgerrits commented 5 years ago

What are the use cases of this?

Seems like there is a standard way to do this at least:

  1. Create a class that conforms with std::allocator if you want a custom allocator. There is even a requirements specification.
  2. Allow for custom allocators in all of our library classes where it makes sense through a template parameter defaulted to std::allocator (This is how std::vector does it)
lokitoth commented 5 years ago

We would need to ensure that this allocator is realloc-compatible, or rethink the realloc codepaths.

In particular, we do realloc here:

There is also a question about passing it in to underlying libraries, e.g. RapidJSON. But that seems to have an allocator interface: https://github.com/Tencent/rapidjson/blob/master/include/rapidjson/allocators.h

A bit of context about realloc and std::allocator: https://stackoverflow.com/questions/6391057/realloc-in-standard-allocator