Has anyone seen an allocator that calls mlock(2) to prevent an STL container's contents from being swapped to disk?
There is afaik only one tricky part to writing such an allocator, namely minimizing the number of mlocked pages by clustering allocations to be mlocked. Ergo, one should probably start by modifying some shared memory allocator?
If I wanted to implement this (which is difficult to imagine, because I find it hard to believe it's the right solution to any problem :^), I'd try to do it by using a boost::pool_allocator
(which provides a standard library compatible Allocator from a pool) and then - I forget the details; think it'll involve the RequestedSize
template argument to singleton_pool
and a user_allocator
? - there will be some way of having that sit on top of a pool which requests bigger chunks of memory by the mechanism of your choice which in your case would be allocation of mlocked pages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With