Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It works with C++ if you use boost::interprocess. Its data structures use offset_ptr internally rather than assuming every pointer is on the heap.


That introduces different data-types, rather than using the existing ones (instantiated with different pointer-types).


Indeed. I don't know if there's a plan for the standard type to move to offset-ptr, or if there's even a std::offset_ptr, but it would be great if there was.

For us, some of the 'different data type' pain was alleviated with transparent comparators. YMMV.

Edit: It seems C++11 has added some form of support for it... 'fancy pointers'

https://en.cppreference.com/w/cpp/named_req/Allocator#Fancy_...


Sure. But that counts as "doing your own relocations". Unsafe Rust could do the same, yes?


I don't know enough about Rust to say. If it doesn't have the concept of a 'fancy pointer' then I assume no, you'd have to essentially reproduce what boost::interprocess does.


I'm still learning Rust, but iiuc you could do this by creating an OffsetPtr type that implements the Deref trait (https://doc.rust-lang.org/std/ops/trait.Deref.html). This is exactly a "fancy pointer" as you describe.


What is being relocated?


If you use offsets instead of pointers you're doing relocations "on the fly"




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: