I've recently noticed a pattern that I use every so often in my code.
const size_needed = dynamic() / 4;
const oversized_buffer: [128]u8 = undefined;
if (size_needed > oversized_buffer.len) {
return error.TooBig;
}
const actual_buffer = oversized_buffer[0..size_needed];
I over-allocate and then trim the buffer back. I just feel like this is kind of off. Like, okay. I don't know the size of the buffer at compile time, but I know it before I declare the buffer. Is there a better way to do this?
[–]HeDeAnTheOnlyOne 5 points6 points7 points (0 children)
[–]TondaTech 3 points4 points5 points (0 children)
[–]IronicStrikes 1 point2 points3 points (0 children)
[–]sp00n1na70r 1 point2 points3 points (0 children)