-
Notifications
You must be signed in to change notification settings - Fork 13
Allocate pointers in deserialize #17
Description
This is a tracking issue for a potential API change: should deserialize be passed an allocator?
While this library is designed not to have any allocations beyond the ArrayList, some issue arises with pointers. For instance, consider the following structure:
const data = .{
// The cast is necessary, otherwise the type is interpreted as `const [0..5]u8`.
.name = @as([]const u8, "James"),
.age = @as(u8, 32),
.company = @as([]const u8, "DEV Inc."),
};When serializing it, then deserializing it, one can not pass the following object:\
var out: @TypeOf(data) = undefined;This is because the compiler will complain that runtime value contains reference to comptime var and note: comptime var pointers are not available at runtime. The undefined will stuff some 0xaaaaaaa values in the pointers, and this will be considered comptime, and no reference can be taken to this fudge value.
So the current approach is to somehow pre-allocate the pointers, which creates a whole host of other issues (e.g. what size should be allocated?).
The only way around this issue that I see for now, is to add a new allocator agument, so that it can be used in this specific instance. Since this is useless most of the time, this could be an optional argument.