REM    _____________________________________________________
REM   |\___________________________________________________/| 
REM   | |                                                 | |
REM   | | SOURCE TITLE:    Memory Reclaim Example         | |
REM   | | ------------                                    | |
REM   | | SOURCE AUTHOR:   Garrett R. Hylltun             | |
REM   | | -------------                                   | |
REM   | | DATE:            04 January, 2001               | |
REM   | | ----                                            | |
REM   | | REQUIREMENTS:    VDS 3.x                        | |
REM   | | ------------                                    | |
REM   | | SOURCE STATUS:   Public Domain                  | |
REM   | | -------------                                   | |
REM   | | SOURCE DESCRIPTION:                             | |
REM   | | ------------------                              | |
REM   | |   This example shows you how to reclaim memory  | |
REM   | | using only VDS itself with no external dlls or  | |
REM   | | other programming languages.                    | |
REM   | |                                                 | |
REM   | |   This does not use the same routine as my      | |
REM   | | Memory-Trax program, which uses another form    | |
REM   | | of memory reclaiming.  This example is pure     | |
REM   | | VDS.  It's slow, but it's very very effect!     | |
REM   | | In most cases during the testing of this, the   | |
REM   | | people who tested it average 83% free memory    | |
REM   | | with every reclaim they did using this          | |
REM   | | method.  Because it was slow, it just wasn't    | |
REM   | | viable for me to use this method in             | |
REM   | | Memory-Trax, even though it was more            | |
REM   | | effective.  The other draw back, is you can't   | |
REM   | | control the actual amount of memory to reclaim  | |
REM   | | like you can in Memory-Trax.  There's just no   | |
REM   | | way to control that with this method.  And      | |
REM   | | trust me, I tried!  In fact, hear me out on     | |
REM   | | this.  I have spent almost a year researching   | |
REM   | | this memory stuff, and spent months on source   | |
REM   | | codes and experiments.  I just could not find   | |
REM   | | a way to control the amount of memory           | |
REM   | | reclaimed using this method.  It basically just | |
REM   | | cleans house, and does a damn good job of       | |
REM   | | doing it.                                       | |
REM   | |                                                 | |
REM   | |   This is also a very simple routine also.      | |
REM   | | You tell the program just how many megs of      | |
REM   | | installed memory you have.  When you reclaim,   | |
REM   | | the routine fills up a list with megs of X's    | |
REM   | | and O's just as filler.. It repeats this until  | |
REM   | | it has filled up the total amount of memory you | |
REM   | | have installed.  Anything that was in memory,   | |
REM   | | is placed in the cache memory.. Anything that   | |
REM   | | didn't belong in memory anymore, is tossed out  | |
REM   | | by windows.  When the process is over, Windows  | |
REM   | | only takes back what is needed for itself to    | |
REM   | | run.  Other programs that were in memory, that  | |
REM   | | are still running, will of course jump back     | |
REM   | | into memory when they do something, or you use  | |
REM   | | them again, but all the memory that was being   | |
REM   | | held by nothing is now cleared and available.   | |
REM   | |                                                 | |
REM   | |   You could automate this in a similar fashion  | |
REM   | | as my Memory-Trax, but you'll need to find a    | |
REM   | | way to grab how much memory the user has        | |
REM   | | installed, instead of having to ask like this   | |
REM   | | example does.                                   | |
REM   | |                                                 | |
REM   | |   Automating shouldn't take too much work.. That| |
REM   | | is, unless you go nuts and make something like  | |
REM   | | I did with Memory-Trax III, which took a year   | |
REM   | | of coding to make.                              | |
REM   | |                                                 | |
REM   | |   Anyway, make someting for yourself at least   | |
REM   | | with this.  This will help keep your system     | |
REM   | | running longer.                                 | |
REM   | |_________________________________________________| |
REM   |/___________________________________________________\|

  DIALOG CREATE,Memory Reclaim,-1,0,170,55
  DIALOG ADD,STYLE,STYLE2,Arial,8,,BLACK,CYAN
  DIALOG ADD,STYLE,STYLE1,Arial,10,B,BLACK,LTGREEN
  DIALOG ADD,TEXT,TEXT1,0,0,200,60,,STYLE1
  DIALOG ADD,TEXT,TEXT2,10,10,,,@name(@div(@sysinfo(freemem),1024)) Mb Free,STYLE1
  DIALOG ADD,BUTTON,BUTTON1,10,98,40,20,Go!
  DIALOG ADD,BUTTON,BUTTON2,10,144,20,20,X
  DIALOG ADD,TEXT,TEXT3,34,12,,,Idle.,STYLE2
:Askforram
REM   --- |-------------------------------------------------| ---
REM   --- |   Since I don't have a pure VDS way to get the  | ---
REM   --- | total physical memory installed, I have to ask  | ---
REM   --- | for how much is installed.  With a dll you      | ---
REM   --- | could probably get the total memory installed,  | ---
REM   --- | and you wouldn't have to ask.                   | ---
REM   --- |-------------------------------------------------| ---
  %%TotalMem = @input(What is your total installed RAM?)
  If @null(%%TotalMem)
    goto Askforram
  End
  DIALOG SHOW
  Option Sleeptime,100

:evloop
  Wait Event,0
  %E = @event()
  If %E
    goto %E
  End
  goto evloop


:Timer
  Dialog Set,TEXT2,@name(@div(@sysinfo(freemem),1024)) Mb Free
  goto evloop

:BUTTON2BUTTON
:Close
  Exit

:BUTTON1BUTTON
REM   --- |-------------------------------------------------| ---
REM   --- |   Ok, here we go.  Follow along now, actually,  | ---
REM   --- | it's not that complicated.  In fact, it's so    | ---
REM   --- | very simple, that I was mad at myself for       | ---
REM   --- | taking so long to figure this out.              | ---
REM   --- |-------------------------------------------------| ---
  Dialog Set,TEXT3,Reclaiming memory / 0
  List create,1
  List create,2
REM   --- |-------------------------------------------------| ---
REM   --- | Here we fill up a list with 1024 bytes          | ---
REM   --- | (characters), and we repeat until we have 1 meg | ---
REM   --- | worth of the list filled.. So there's going to  | ---
REM   --- | be 1024 entries in this list, each with 1024    | ---
REM   --- | characters, adding up to a total of 1 meg.      | ---
REM   --- |-------------------------------------------------| ---
  Repeat
    List Add,1,1OXOXOXOXOXOXOXOXOXOXOXOXOXOXOX0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0
    %%Null = @sum(%%Null,1)
  Until @equal(%%Null,1024)
  %%Null = 
REM   --- |-------------------------------------------------| ---
REM   --- |   Now that we have 1 meg in the first list,     | ---
REM   --- | it's time to go full force into the memory      | ---
REM   --- | reclaim.  We do this by taking the number of    | ---
REM   --- | megs the user has installed for memory, and     | ---
REM   --- | filling up a second list with that amount.  We  | ---
REM   --- | have 1 meg in our first list, and we will now   | ---
REM   --- | repeat the next loop as many times as the       | ---
REM   --- | user has megs of memory.  So if the user has    | ---
REM   --- | 256 megs of memory, we will loop 256 times,     | ---
REM   --- | which means, we will have just stuffed 256      | ---
REM   --- | megs of X's and O's into the memory,            | ---
REM   --- | completely pushing out anything and everything  | ---
REM   --- | else.  Anything that wasn't being held by a     | ---
REM   --- | program, is tossed.. Which is what we want,     | ---
REM   --- | because that's what was holding up the extra    | ---
REM   --- | memory in the first place.  Everything else is  | ---
REM   --- | placed in cache, and is still available to your | ---
REM   --- | system.  When it's needed again, it's brought   | ---
REM   --- | back into the physical memory.                  | ---
REM   --- |-------------------------------------------------| ---
  Repeat
    List Add,2,@text(1)
    %%Null = @sum(%%Null,1)
    Dialog Set,TEXT3,Reclaiming memory / %%Null
  Until @equal(%%Null,%%TotalMem)
  List Clear,1
  List Close,1
  List Clear,2
  List Close,2
  Dialog Set,TEXT3,Idle
  goto evloop
REM   --- |-------------------------------------------------| ---
REM   --- |   And that's it!  Basically, Windows really     | ---
REM   --- | weeds out the the stuff that was stuck in       | ---
REM   --- | memory, we are just forcing windows to do it    | ---
REM   --- | since it was not able to do it on it's own.     | ---
REM   --- |-------------------------------------------------| ---