freeing ram (aka ram defragmentation)?

Just starting out? Need help? Post your questions and find answers here.
muab256
User
User
Posts: 43
Joined: Mon Apr 28, 2003 4:57 pm

freeing ram (aka ram defragmentation)?

Post 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
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post 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..
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post by dmoc »

muab256
User
User
Posts: 43
Joined: Mon Apr 28, 2003 4:57 pm

Post 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
RJP Computing
Enthusiast
Enthusiast
Posts: 202
Joined: Sun Apr 27, 2003 4:44 am
Location: Michigan, USA
Contact:

Post by RJP Computing »

I agree.
I would love to do this also.
Great question.
-Ryan
RJP Computing

Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
DEU.exe
User
User
Posts: 13
Joined: Sun Oct 19, 2003 11:21 am
Location: www

Post 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.
pIII@1Ghz, wXP, 512MB, pb3.93full
muab256
User
User
Posts: 43
Joined: Mon Apr 28, 2003 4:57 pm

Post by muab256 »

doesnt this one work under win2000 or am i just too stupid to
read my ram monitor? ;(
Fred
Administrator
Administrator
Posts: 18256
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post 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.
muab256
User
User
Posts: 43
Joined: Mon Apr 28, 2003 4:57 pm

Post 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
DEU.exe
User
User
Posts: 13
Joined: Sun Oct 19, 2003 11:21 am
Location: www

Post 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.
pIII@1Ghz, wXP, 512MB, pb3.93full
muab256
User
User
Posts: 43
Joined: Mon Apr 28, 2003 4:57 pm

Post 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 ;/
DEU.exe
User
User
Posts: 13
Joined: Sun Oct 19, 2003 11:21 am
Location: www

Post 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.
pIII@1Ghz, wXP, 512MB, pb3.93full
muab256
User
User
Posts: 43
Joined: Mon Apr 28, 2003 4:57 pm

Post 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
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Re: freeing ram (aka ram defragmentation)?

Post 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
muab256
User
User
Posts: 43
Joined: Mon Apr 28, 2003 4:57 pm

Post 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
Post Reply