You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In complex functions or nested structs, this gets tedious.
There's a case to be made for why that's good – discouraging dynamic allocations means people will usually write faster software. That being said, sometimes the only sane thing is dynamically allocate.
In complex functions or nested structs, this gets tedious.
This should only be tedious for init(bar: *Bar).
Also, this sounds like a bunch of local optima to me, because it only works nicely with primitive/simple types or breaks weak coupling.
Can you provide examples with estimations of amounts in a realistic code base ?
I don't think this is a good idea as it might introduce unnecessary copies and temporaries, as well as breaking result locatation. This means that types that require result location semantics can't be constructed with allocator.new, but the function basically hides that fact.
Also how does this work with types that are sequentially initialized (piece by piece)?
Imho this proposed API has more footguns than benefits
Related to #11479, but not the same
Currently, to create a new allocated type:
In complex functions or nested structs, this gets tedious.
There's a case to be made for why that's good – discouraging dynamic allocations means people will usually write faster software. That being said, sometimes the only sane thing is dynamically allocate.
Suggestion
What if
std.mem.Allocator
had anew
function?Why
new
as the name?It is a similar convention used by other languages, so it should be easy to learn
Example implementation:
Once #7772 is implemented, perhaps
value
would beinline
and there would be zero difference in performance:The text was updated successfully, but these errors were encountered: