MemoryLayout

Is there anything akin to MemoryLayout that can be used in Silver? My immediate need is to find out the size of a C struct, but I’m sure other uses will follow in the near future.

what platform?

Our existing code is for macOS. The target is .NET, and later Android, iOS, and Linux (in priority order).

Hmm. we don’t currently provide something like this, but pretty much the only place where it could feasibly be done is for Cocoa and Island. Bon .NET and Java you cannot really access or depend omg the physical memory layout of anything via unsafe pointers.

What’s the actual (logical) goal you’re trying to achieve?

I’m interfacing to external libraries with a C API. Some of the functions return pointers to C structs, and I need to know the size of the struct.

the size of structs can be gotten with with https://docs.elementscompiler.com/API/SystemFunctions/SizeOf

in swift this would translate to: sizeOf(MyType)

Let me know if you find a use case for the align of and stride, if needed we can add or workaround that.

Thanks. At the moment I don’t need them, but it might change in the future. Some of the libraries I have used in the past are strict about alignment.

Yeah. Note that Island and .NET both should have fairly sane alignments, and both allow for packing (via structlayout on .net, and [Packed]/@Packed attributes on Island)