Custom smart pointer with allocator API

I am currently trying to add support for the nightly allocator API to my custom smart pointer type (GitHub - luca3s/simple-left-right: real-time lockfree data sharing library for reference).
I am unsure where i should store the allocator. The standard Library Arc stores it on the stack with every single Arc, but my first idea was to put it inside the allocation. That would no longer require A: Clone and would need (a tiny bit) less memory. More importantly the inner struct (that is on the Heap) can deallocate itself and it is clearer that the same allocator was used to allocate and deallocate.

Is there anything i missed? why aren't the std smart pointers structured this way?

I believe that standard library stores allocators inline, because it assumes that most allocators will be ZST (zero sized types). Then cloning it and storing doesn't matter and as with all ZST they are only compile time construct, and simply disappear at runtime.

1 Like