Page 1 of 2

freeing ram (aka ram defragmentation)?

Posted: Sat Oct 18, 2003 5:53 pm
by muab256
heyas!

id like to write a tiny tool to "completely" free my ram (also known as
defragment ram).

think this is done by filling my complete ram with some data so other
stuff is removed/moved to swap, and then releasing (clean) the used
ram again... right?

so how could i fill the ram?

thx
muab

Posted: Sat Oct 18, 2003 7:09 pm
by Karbon
Allocating memory is pretty easy but managing it on the level you'd lik eto probably isn't (though I can't say for sure!)..

PureBasic has several native functions for memory manipulation, check out the memory lib in the documentation.. There are also lots of Win API functions to deal with memory (GlobalAlloc_() and HeapAlloc_() to name a few).. You'll have to look those up in Microsoft's documentation..

Posted: Sat Oct 18, 2003 10:28 pm
by dmoc

Posted: Sat Oct 18, 2003 11:20 pm
by muab256
thats the one i actually use =)
i prefer having tools i can _really_ control though, also i thought
this is a quite interesting question =P

Posted: Sun Oct 19, 2003 2:02 am
by RJP Computing
I agree.
I would love to do this also.
Great question.

Posted: Sun Oct 19, 2003 11:26 am
by DEU.exe
Hi,
try this one:

Code: Select all

;
; FreeRAM
;
*freecache=AllocateMemory(1,100000000,0)
;
;if you have 128MB RAM 
;100000000 = ca. 3/4 of the installed memory
:D

F.

Posted: Sun Oct 19, 2003 11:39 am
by muab256
doesnt this one work under win2000 or am i just too stupid to
read my ram monitor? ;(

Posted: Sun Oct 19, 2003 11:58 am
by Fred
Windows doesn't map a ram area if it's not used. So just very a byte at the very end of the buffer an d the whole ram will be allocated.

Posted: Sun Oct 19, 2003 12:05 pm
by muab256
Fred wrote:Windows doesn't map a ram area if it's not used. So just very a byte at the very end of the buffer an d the whole ram will be allocated.
umm... and how would i do that? ;P

Posted: Sun Oct 19, 2003 12:06 pm
by DEU.exe
I didn't test it, but in Visual Basic it works like this:

Code: Select all

;
; Visual Basic Code !!!!!!!!!!!!!!!!!!!
;
a=string(100000000,"x")
The script request 100MB for the string, and frees the memory if it ends.
In PB you may have to fill the Memory with some values.

F.

Posted: Sun Oct 19, 2003 12:16 pm
by muab256
DEU.exe wrote: The script request 100MB for the string, and frees the memory if it ends.
In PB you may have to fill the Memory with some values.
F.
theres a problem: a string is limited to 65535 chars ;/

Posted: Sun Oct 19, 2003 12:53 pm
by DEU.exe
muab256 wrote:
Fred wrote:Windows doesn't map a ram area if it's not used. So just very a byte at the very end of the buffer an d the whole ram will be allocated.
umm... and how would i do that? ;P
It could work like this:

Code: Select all

*freecache=AllocateMemory(1,100000001,0)
PokeB(*freecache+100000000,1)
F.

Posted: Sun Oct 19, 2003 3:32 pm
by muab256
didnt work either =(

Code: Select all

to_free=192

Dim mem_filler.s (1024)
mb.s="X"
For n = 1 To 10 : mb=mb+mb : Next

For mb_count=1 To to_free
   mem_filler(mb_count)=mb
Next

Delay(10000)

End
same to this "solution"... it is never used more than 1.5mb ;(

muab

Re: freeing ram (aka ram defragmentation)?

Posted: Mon Oct 20, 2003 12:02 am
by NoahPhense
Sorry, was goofin around.. maybe this will give you some ideas... I personally wouldn't use it. Because of the time it takes to load the variables.. but I'm sure Fred could point you in the right direction.

I use MemTurbo myself.. on an Ultra stable 2k platform.. love it, will not use anything else.. unless of course I created it myself.. ;)

Code's a bit sloppy..

Screen shots of MEMTURBO 2 (below)

Code: Select all

DefType.s a, b, key

NewList memBlock.s()


If OpenConsole()
    ConsoleTitle("Windoze eat your heart out...")
    ClearConsole()
    PrintN("")
    Print("How many megs do ya want to eat up: ")
    HowManyMegs$ = Input()
    mbs.w = Val(HowManyMegs$)
    PrintN("")
    
    Gosub LoadVariables
    
    For x = 1 To (mbs*20)
        AddElement(memBlock())
            memBlock() = a
    Next x

    For x = 1 To mbs
        AddElement(memBlock())
            memBlock() = b: ; lets add on 24k per mb that the user selected, you know 1024k ..
    Next x

    PrintN("smash a key...")
    Repeat
        key = Inkey()
    Until key<>""
    CloseConsole()
EndIf

ClearList(memBlock())
    
End


LoadVariables:
PrintN("")
PrintN("Please standby, loading variables...")
For x = 1 To 49999: ; did this because a string is really length of string +1..   wanted 50k per block
    a = a + "a"
Next x

For x = 1 To 23999: ; same, wanted 24k block.. for the 1024k
    b = b + "b"
Next x
PrintN("..variables loaded")
PrintN("")
Return
Image

Image

Image

- john

Posted: Mon Oct 20, 2003 8:11 am
by muab256
this one looks nice =)

at least it works, ur right, its not the fastest solution, but
- one can try to make it better
- its way not as slow as i expected after reading ur post ;P

many thx