News for hackers. Stuff that matters.
Re:Ron: Rusty Object Notation by dmytrish on Sunday April 23, 2023 @01:05PM (#35678090)
It's a shame you're being downvoted, it's a perfectly valid question.

It is possible to do explicitly with `#[repr(C)]` in Rust. This is still fragile:

- `usize` and `isize` are not guaranteed to be portable between machines.

- pointers (including vtables in trait objects) are not portable between processes

- structs and enums may change in source code

- file descriptors, mutexes/futexes and any kind of external resources in general are not portable between processes. Thread-local variables are not even portable between threads.

In short: memory layout in general depends on a large amount of ephemeral compiler metadata. It is possible to constrain memory layout to something portable (protobufs, flatbuffers, capnproto, thrift, etc), but this seems more like a serialization format, not an efficient memory layout for a compiled language.

I'd say this is a good thing to avoid ossification of memory layouts: if you need to unmarshal something, it is better to mark this explicitly. Although the C ABI can be convenient, it constrains optimizations that compilers are allowed to do.

There are no comments on this comment yet.