3 ms·
> read past the buffer "if you can tell your compiler that the string you receive is ‘padded’ so that you can read eight bytes safely from it." But even if yo
by Dylan16807 4y ago
> read past the buffer
"if you can tell your compiler that the string you receive is ‘padded’ so that you can read eight bytes safely from it."
But even if you can't make that guarantee, this still works pretty well as a performance comparison, you just need to make sure your final code has a runtime length check.
- vlovich123 4y agoAnd that your allocation isn’t at the end of a page.
- Dylan16807 4y agoIf you legitimately have the buffer length then it doesn't matter how the allocation is aligned. The extra time to read the next page with no errors doesn't need to be avoided, since it's rare and you're very likely to use that data anyway. The only thing you need is certainty that you have the buffer length.
- vlovich123 4y agoYou're assuming the next page is mapped. If it's pointing into unmapped memory, then you'll segfault.
- Dylan16807 4y agoI'm not assuming. When I say "guarantee", I mean the code is designed so the first 8 bytes are always mapped. When I say "runtime length check", I mean the code only runs if the first 8 bytes are in fact mapped. No assumptions. No possible way to segfault. The read is valid. If buffer[6] is not mapped, then you don't "legitimately have the buffer length".
- vlovich123 4y agoOk then I just misunderstood / some kind of language preciseness confusion. We’re on the same page now. AFAIK this is what the article is saying to do.
- Dylan16807 4y ago> AFAIK this is what the article is saying to do. Yeah, that's why I quoted the article.