c++ - Keeping memory usage within available amount -
i'm writing program (a theorem prover happens) memory requirement "as possible, please"; is, can better using more memory, practical purposes without upper bound, needs use memory available, no more , no less. can figure out how prioritize data delete lowest value stuff when memory runs short; problem i'm trying solve how tell when happening.
ideally system call returns "how memory left" or "are out of memory yet?"; far can tell, no such thing exists?
of course, malloc can signal out of memory returning 0 , new can call handler; these aren't ideal signals, better nothing. problem, however, want know when physical memory running out, can avoid going deep swap , thereby making grind halt; don't suppose there's way ask "are having swap yet?" or tell operating system "don't swap on account, fail requests if comes that"?
another approach find out how ram in machine, , monitor how memory program using @ moment. far know, there no way tell former? impression there no reliable way tell latter except wrapping malloc/free bookkeeper function (which more problematic in c++).
are there approaches i'm missing?
the ideal portable solution, suspect that's not going happen. failing that, solution works on windows , 1 works on unix nice. failing that, solution works on windows , 1 works on linux.
i think useful , flexible way use memory available let user specify how memory use.
let user write in config file or through interface, create allocator (or similar) not provide more memory.
that way, don't have find statistics current computer allways biased fact os run other programs well. don't talk way os manage cache, differences between 32 , 64 bit making adress space limit allocations etc.
in end, human intelligence (assuming user know context of use) cheaper implement when provided user.
Comments
Post a Comment