Reputation: 3075
I am working on a heavy weight application where the application is the only application runing on the system. On a recent performance run it was found that we were taking a lot of time in derefereing a very large vector of pointers . I found that we have large swapin/out as well giving me an indication that may be the vector element memory was released from ram. Can I ensure that my elements pointed to by pointers which are contained in my vector never go out of ram . Gcc 4.8 and Not c++11 . Red hat v6.5 . We cant use c++ 11 as per management dicission .
Upvotes: 0
Views: 284
Reputation: 86353
You can't solve this problem using any C++ language features. What you need is support from the operation system.
Luckily Linux offers an API that lets you mark memory pages that should not get swapped out. You'll find these in mman.h: mlock man page
So if you want your vector to always be present in RAM you should:
Keep in mind: The OS will not swap out memory for no reason. If part of your vector reside on the harddisk, something else you've accessed recently was more important. If you start experimenting with unswappable memory be ready for some performance surprises. The OS already tries to do it's best.
Upvotes: 3