#Getting a []const u8 from a Struct with format defined?
1 messages · Page 1 of 1 (latest)
use an ArrayLists’s writer’s print method
var arr = ArrayList(u8).init(alloc);
const writer = arr.writer();
try writer.print(“{}\n”, {thing});
I used printAlloc is there benefits to doing ArrayList instead?
oh no thats probably better lol, forgot about that
Depends on your usage
If you have many prints that should end up in a single slice ArrayList is the way
Also, printAlloc runs format twice (the first one is to figure out the exact required allocation size), so if your format method is expensive it could be worth considering the ArrayList approach
why does it do this?
i just checked the code, and I dont understand why it doesnt just make an ArrayList(u8) and use it's writer
maybe that's slower somehow than running format twice 🤔
i doubt that
id guess so its only 1 allocation
not sure thats a great reason tho
im gonna benchmark perf :P
i also think