4 ms·
> Between every pair of adjacent elements, this vector allocated a dummy page, marked as un-readable and un-writeable. Any attempt to access it would immediatel
by sapiogram 3y ago
> Between every pair of adjacent elements, this vector allocated a dummy page, marked as un-readable and un-writeable. Any attempt to access it would immediately trigger a segfault.
I'm struggling to figure this one out. Essentially every two elements would be stored at the start and end of a page, respectively? Followed by a dummy page?
8KB per pair of elements I guess, hope your vectors weren't too large :p
- jesse__ 3y agoIt's probably between blocks of elements. Like, when the vec needs to realloc they insert a guard page. This is a pretty common allocator trick
- CoastalCoder 3y agoSorry, let me clarify. Suppose you have a vector with 3 elements, and each individual element fits within a single memory page. Then the array layout is: page[0] : dummy page page[1] : element 0 page[2] : dummy page page[3] : element 1 page[4] : dummy page page[5] : element 2 page[6] : dummy page IIRC. It's been a while :)