Replies: 2 comments 6 replies
-
Thanks for asking! Except for global threadsafe shared resources like the system's malloc allocator, an allocator is a container, a whole, and the things allocated within it are its parts. They can be projected out of the allocator. That's the only way to maintain MVS. It many not even make sense to think of the allocator as an allocator; you might think of it as a heterogeneous container. The exact way that memory is acquired by the allocator and apportioned to the allocator's parts is of course dependent on the allocation strategy (arrays of raw bytes can work, with some bookkeeping). The illusion presented by C++ that there is no whole-part relationship between the allocator and things stored in it cannot be upheld, so the ergonomics will be different. And that's about as much as I know for sure at this point. Whether it's reasonable for vocabulary collection types to be able to expose borrowed memory, or whether you need a separate family of collection types that can be projected out of allocators, is an open question. Implicits (implicit function arguments) may have a role to play in keeping usage ergonomic also; they can help hide the passing-around of context. But knowing more is going to take some experimentation, so I encourage you to dig into the problems yourself and see what you come up with. |
Beta Was this translation helpful? Give feedback.
-
I'm having trouble understanding this:
I guess one way to understand it is that the API can be implemented by a model having only safe operations. But in a generic context, it seems to me it's obviously unsafe, because |
Beta Was this translation helpful? Give feedback.
-
This is a similar question to https://github.com/orgs/hylo-lang/discussions/736 but specifically about custom allocators. The general pattern in languages like C++ and Rust is to store a pointer/reference to the allocator, but that breaks MVS. I also don't think it always makes sense for a collection to own its allocator. For example, you might want to use a bump allocator to pack a bunch of heterogeneous objects together in memory. Is there an ergonomic solution to this that doesn't sacrifice MVS? I really like the design of Hylo, so I'm hoping there is. An obvious but undesirable solution would be an array of union objects, but that has multiple inefficiencies.
Beta Was this translation helpful? Give feedback.
All reactions