Why std.Io.Writer interface design is different from std.mem.Allocator interface in 0.15.1

I think this discussion is drifting off-topic. Maybe discussing about the meaning of “interface” could be moved to a different thread?

Back to the question:
In fact the OP’s question was more or less solved right at the beginning:
It’s a question of memory overhead and performance.
There are many, many allocations*) in a program, and it was seen that the Allocator style is better than the @fieldParentPtr style of a writer in this scenario.

*) …unless the program is explicitly written with a goal to avoid this.

But it’s worth mentioning that the Writer has a fundamental different usage scenario:

The writers are written in such a way that VTable calls are more or less only needed when the buffer is full (ie rarely), and in that case, there is actually some heavy work to do (eg syscalls).
And in this scenario, the overhead for the VTable call is absolutely neglectable, so the @fieldParentPtr way “wins” here.

2 Likes