Ooops
October 28, 2020, 11:41:09 PM

Author Topic: [bmx] Memory Monitor by Mark Tiffany [ 1+ years ago ]  (Read 1597 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] Memory Monitor by Mark Tiffany [ 1+ years ago ]
« on: June 29, 2017, 12:28:43 AM »
Title : Memory Monitor
Author : Mark Tiffany
Posted : 1+ years ago

Description : Include the code below into your source (suggest you wrap the include with ?debug) to get a small GUI window that will show current memory usage, without having to amend any of your code.  Very handy for tracking down memory leaks!

Code :
Code: BlitzMax
  1. Global memcheckwin:Tgadget
  2. Global memchecktimer:TTimer
  3.  
  4. memchecktimer=CreateTimer(10)
  5. AddHook EmitEventHook , _memcheck_hook,memchecktimer
  6.  
  7. Function ShowMem()
  8.         Local m:Long
  9.         If memcheckwin = Null Then
  10.                 memcheckwin = CreateWindow("Memory Usage" , GadgetWidth(Desktop() ) - 250 , 0 , 250 , 30 , Null , WINDOW_TITLEBAR)
  11.         End If
  12.         GCCollect()
  13.         m = GCMemAlloced()
  14.         SetGadgetText memcheckwin , "Memory Usage: " + m
  15. End Function
  16.  
  17. Function _memcheck_hook:Object(id:Int , data:Object , context:Object)
  18.         Local e:TEvent
  19.         e=TEvent(data)
  20.         If e.source = memchecktimer And e.id=EVENT_TIMERTICK Then
  21.                 ShowMem()
  22.                 Return Null
  23.         Else
  24.                 Return data
  25.         End If
  26. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal