I am using shared memory to transfer a large amount of data between processes. This data is mostly formed of an array of structs, to do this, these structs needs to have consistent ordering across processes (e.g. extern struct). In trying to do this I encounter the error: error: extern structs cannot contain fields of type 'array_list.ArrayListAligned(u8,null)'
E.g.:
const MyType = extern struct {
const Self = @This();
fd: i32,
data: std.ArrayList(u8),
fn init(allocator: Allocator, fd: i32) !Self {
const arr = try std.ArrayList(u8).init(allocator);
return Self {
.fd = fd,
.data = arr
}
}
}
fn main() !void {
var buffer: [100_000]u8 = undefined; // This would be the shared memory
var fba = std.heap.FixedBufferAllocator.init(&buffer);
const allocator = fba.allocator();
var snapshots = std.ArrayList(MyType).init(allocator);
snapshots.append(MyType.init(allocator,21));
}
I could implement my own version of ArrayList here to solve this, but I really don't want to do this. Is there a way to apply extern to external structs?