Is there a way to control the address an object will be allocated at in Swift? I know Objective-C has this feature (although it's hidden away in the runtime), and C++ has placement new, but I don't see a way to do it in pure Swift.
Although the UnsafeMutablePointer
type may be used to store arbitary objects (using it's initialize...
methods), those methods require that the source object already exists, which requires an extra memory allocation and copy.
I've used this technique for doing IPC with memory-mapped files before, but I'd like to write some of my newer side-projects in Swift...
UnsafeMutablePointer<Memory>.initialize...()
functions seem to require that the objects they're being initialized with already exist somewhere. I'd like to avoid the extra allocation and copy if possible.