Memory regions

Is there a mechanism by which one can limit pointers to a specific region in memory?

We cannot afaik forbid borrows from pointing to anywhere in memory. We could maybe limit ourselves to 'static types, but this does not prevent &'static borrows.

We could've an Allocator which only created pointers into the target region, but we cannot necessarily preclude a user defined type using a different Allocator internally.

You'd just want an unsafe trait which made these promises I guess? I'm wondering specifically about mmapped files which one always mmaps into the same memory region, and contain internal owned pointers, but not necessarily internal borrows.

What do you mean by "limit"? What are you hoping to do with this limitation? How do you want to consume such pointers?

Ideally I'd want a Box<T,MMaped<MyRegion>>, Vec<T,MMaped<MyRegion>> which demands T: InMMap<MyRegion> and then T: InMMap<MyRegion> says any pointer P obtained from T satisfies P: InMMap<MyRegion>.

We probably cannot really enforce something like this, not without doing this check in code outside rustc, maybe some proc macro doing the unsafe impl<..> InMMap<MyRegion> for .. bits. It's useful because it lets you have owned pointers within an mmapped file, not portable but very fast.

This topic was automatically closed 540 days after the last reply. New replies are no longer allowed.