Limbic~Region has asked for the wisdom of the Perl Monks concerning the following question:
The current method I intend to use starts out requiring only very little memory, peaks half way through the solution, and then tapers off. It looks a little bit like this:
my $old_work = get_initial_work(); # hash reference my $new_work = {}; while (%$old_work) { for my $item (keys %$old_work) { my $job = delete $old_work->{$item}; for (new_work($job)) { $new_work{$item . $_} = $_; } } ($new_work, $old_work) = ({}, $new_work); }
While I can easily determine the upper boundary memory requirement for any board, I can't know for sure how close to that boundary the code will actually get. One way to approach this would be to allow the user indicate the maximum amount of memory they are willing to spend and if the upper boundary exceeds that amount - resort to BerkeleyDB. This is an "all or none" approach.
I can improve upon this a bit because I can calculate the upper boundary memory requirement for each pass through the work process. I can switch between in-memory and BerkeleyDB as soon as I know I might exceed the user-defined threshold and then revert as soon as I know that I won't. This is a "per-pass" approach and is the strategy I plan on using at the moment.
What I would like to do however is make the switch only if I actually do approach the limit. So I would need to know the memory consumed by ($old_work + $new_work) and have a way of switching to BerkeleyDB. For now I am knowingly ignoring lots of details such as Perl not necessarily freeing memory to the OS. What I am interested in knowing is:
The reason I would like to do this is that many board configurations are likely impossible due to the constraints of the game. Only valid configurations are visited so the actual memory consumption may never approach the upper boundary and keeping things in memory will certainly be faster. Thanks in advance for your time and consideration in this matter.
Cheers - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Dynamically switching between in-memory and disk-tied data structures
by BrowserUk (Patriarch) on Nov 07, 2006 at 17:59 UTC | |
|
Re: Dynamically switching between in-memory and disk-tied data structures
by perrin (Chancellor) on Nov 07, 2006 at 17:02 UTC | |
|
Re: Dynamically switching between in-memory and disk-tied data structures
by Anonymous Monk on Nov 07, 2006 at 17:11 UTC |