Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a C++ allocator that prevent an STL container from being swapped?

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?

like image 223
Jeff Burdges Avatar asked Oct 09 '22 21:10

Jeff Burdges


1 Answers

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.

like image 80
timday Avatar answered Oct 12 '22 10:10

timday