Beej Jorgensen@lemmy.sdf.org to Programming@programming.dev · 1 day agoUsing black magic to make a fast circular buffer.lo.calho.stexternal-linkmessage-square3fedilinkarrow-up122arrow-down10file-textcross-posted to: hackernews
arrow-up122arrow-down1external-linkUsing black magic to make a fast circular buffer.lo.calho.stBeej Jorgensen@lemmy.sdf.org to Programming@programming.dev · 1 day agomessage-square3fedilinkfile-textcross-posted to: hackernews
minus-squareTechnus@lemmy.ziplinkfedilinkarrow-up4·1 day agoThis is a neat trick but it works best on Linux and maybe macOS. Implementing it on Windows requires some luck as you can’t just map adjacent pages, you have to just request two of them and hope the OS gives you two contiguous ones. For example, see this abandoned Rust crate: https://github.com/gnzlbg/slice_deque/blob/045fb28701d3b674b5da413266ca84b3e5a70190/src/mirrored/winapi.rs#L57
This is a neat trick but it works best on Linux and maybe macOS.
Implementing it on Windows requires some luck as you can’t just map adjacent pages, you have to just request two of them and hope the OS gives you two contiguous ones. For example, see this abandoned Rust crate: https://github.com/gnzlbg/slice_deque/blob/045fb28701d3b674b5da413266ca84b3e5a70190/src/mirrored/winapi.rs#L57