Re:Handles Are the Better Pointers (2018)
by gumby on Thursday August 13, 2020 @01:02PM
(#24145533)
It’s trivial to do this in C++ and often the caller doesn’t even realize.
[ Parent
| on HN ]
Re:Handles Are the Better Pointers (2018)
by aks_tldr on Thursday August 13, 2020 @07:40PM
(#24151242)
do you have any pointers of such implementation ?
We have a mixin class that will allocate a subclass with its own array of handles (the handles overload * and -> so they act like pointers). If you have an instance variable you can choose to give it a different allocator, where that instance variable of object with handle `n` is the nth object in the new area. Then your instance method `barf& foo();`, instead of getting the instance variable `barf m_foo` Instead does some inlined arithmetic and gives the caller a reference to the object.