View Full Version : memcleaner question :)
Lionheart008
18-04-2009, 20:41
good evening :)
...one stupid question:
what does it mean: 'heap memory'??? Overload it or make mem space free ??? I allocate it and then I deallocate (delete) it again ??? :? I was looking for such things as memcleaner :)
uses "UI"
dim pMem, pMem2 as long
pMem = heap_alloc(1024*1024)
if pMem then
msgbox 0, "Allocated " & FORMAT$(heap_size(pMem)/1024, "#,") & " Kbytes at " & pMem & " memory location", %MB_Iconinformation, "MemCleaner example"
ELSE
msgbox 0, "Cannot allocate"
ENDIF
heap_free(pMem)
pMem2 = heap_alloc(1024*1024*768) ' *1024 gives error message for my notebook ;)
if pMem2 then
msgbox 0, "Allocated " & FORMAT$(heap_size(pMem2)/1024, "#,") & " Kbytes at " & pMem2 & " memory location", %MB_Iconinformation, "MemCleaner example"
ELSE
msgbox 0, "Cannot allocate"
ENDIF
heap_free(pMem2)
msgbox 0, "Deallocated", %MB_Iconinformation, "MemCleaner example, finished :) "
bye, Lionheart and thanks for answer ;)
Petr Schreiber
18-04-2009, 20:47
Hi Frank,
do you remember the dark times of Win98/ME?
When you used of programs, memory got fragmented, you got less and less of it so you had to restart to work comfortably.
Heap_Alloc simply allocates empty space at programmers disposal in system memory.
When you request to allocate bigger part of memory, Windows realises it should clean up (in fact it seeks space for the new object), so it sort of defragments the memory.
I used this technique (by creating gigantic string) on WinME, it saved me few restarts a day.
This is no longer needed WinXP+
In this example allocating and deallocating simply "fixes" the memory layout, but Heap_Alloc can be great helper for more practical tasks, where you need to manage memory dynamically.
ErosOlmi
18-04-2009, 20:53
Heap memory is a memory block allocated by the application via indirect pointer in the stack
http://www.c-sharpcorner.com/UploadFile/rmcochran/csharp_memory01122006130034PM/Images/heapvsstack2.gif
Than with that block of memory you can do what you want.
It is programmer responsibility to free heap memory when not needed anymore. If not free, it will remain allocated till the end of the process.
In old operating system (Win9x) memory not free by an application remained allocated till the computer was restarted or generated GPF or hanged up the computer.
On 32bit Windows Versions the OS take care to de-allocated all memory used by an application even if the programmer didn't free all dynamically allocated memory blocks.
It is always good practice to take note of the allocated blocks using returned pointer and free them when is the right time.
Lionheart008
18-04-2009, 20:58
thank you petr ! :) oh yes, I can remember it very good, so I have managed some big 3d graphic tests scene and so I have used some times a memcleaner, but wasn't sure if this little software did really worked fine for me ;)
ps: when I am increase the third value to *1024 I got an error message and window xp say goodbye to me :)
pMem2 = heap_alloc(1024*1024*1024)
funny :)
ps: !
I use "ClearProg" to clear my software caches and cookies... it's possible to make with thinbasic such a little tool??? I want to say "yes, of course" ! Isn't it??? :D
Lionheart008
18-04-2009, 21:00
thank you eros too :) your post was one second faster than my input here ! :D
good to know such things and I understand the little script I have changed a little... ;)
so memcleaner makes no sense with/for win xp as petr said ??? good to know!
On 32bit Windows Versions the OS take care to de-allocated all memory used by an application even if the programmer didn't free all dynamically allocated memory blocks.
It is always good practice to take note of the allocated blocks using returned pointer and free them when is the right time.
thank you! :)
ciao, Lionheart
ErosOlmi
18-04-2009, 21:06
ps: when I am increase the third value to *1024 I got an error message and window xp say goodbye to me :)
pMem2 = heap_alloc(1024*1024*1024)
Do you know how much memory are you asking to the OS with 1024*1024*1024 :D
Quite easily the OS will say: hey, what are your doing? Consider 32bit OS can handle up to 4Gb and every application has a max of 2Gb of virtually allocable memory
http://www.microsoft.com/whdc/system/platform/server/PAE/PAEmem.mspx
Lionheart008
18-04-2009, 21:09
... so I have got it: a warning message by microsoft followed and said: my virtually memory collapsed :D (1024*1024*1024) must laugh ...
thanks again...