User Tools

Site Tools


memory_20usage_20monitor

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

memory_20usage_20monitor [2018/03/31 13:19]
127.0.0.1 external edit
memory_20usage_20monitor [2018/04/17 17:45]
tbest3112 Added syntax highlighting
Line 2: Line 2:
  
 //by Richard Russell, May 2007//\\ \\ **//This facility is now more conveniently available as an [[/​Tools%20and%20Utilities|Add-In Utility]]//​**\\ \\  It is sometimes useful to be able to monitor memory usage (for example heap and stack size) while a program is running. This can alert you to problems like a //memory leak// (increasing and irreversible use of memory, eventually resulting in a 'No room' error) or wasteful use of memory resources (e.g. excessive string //​garbage//​).\\ \\  Whilst you can always add your own code to monitor and report memory usage, it can be inconvenient and awkward to do so without disrupting your program'​s normal operation. This article lists a short routine which you can include in any program, which reports memory usage in a separate window:\\ \\ {{monitor.gif}}\\ \\  The routine can most easily be activated by means of an [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwin6.html#​ontime|ON TIME]] interrupt, allowing it to run whatever your program is doing (within reason) and with the minimum need for modification to your program. Simply add the following statement near the beginning of your program:\\ \\  //by Richard Russell, May 2007//\\ \\ **//This facility is now more conveniently available as an [[/​Tools%20and%20Utilities|Add-In Utility]]//​**\\ \\  It is sometimes useful to be able to monitor memory usage (for example heap and stack size) while a program is running. This can alert you to problems like a //memory leak// (increasing and irreversible use of memory, eventually resulting in a 'No room' error) or wasteful use of memory resources (e.g. excessive string //​garbage//​).\\ \\  Whilst you can always add your own code to monitor and report memory usage, it can be inconvenient and awkward to do so without disrupting your program'​s normal operation. This article lists a short routine which you can include in any program, which reports memory usage in a separate window:\\ \\ {{monitor.gif}}\\ \\  The routine can most easily be activated by means of an [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwin6.html#​ontime|ON TIME]] interrupt, allowing it to run whatever your program is doing (within reason) and with the minimum need for modification to your program. Simply add the following statement near the beginning of your program:\\ \\ 
 +<code bb4w>
         ON TIME PROCmonitor : RETURN         ON TIME PROCmonitor : RETURN
 +</​code>​
 This assumes you don't already have an **ON TIME** interrupt; if you do, add **PROCmonitor** to the code executed in the interrupt routine.\\ \\  The values reported by **PROCmonitor** are as follows:\\ \\  This assumes you don't already have an **ON TIME** interrupt; if you do, add **PROCmonitor** to the code executed in the interrupt routine.\\ \\  The values reported by **PROCmonitor** are as follows:\\ \\ 
  
Line 11: Line 13:
   * Free heap/stack: the amount of memory available for growth of the heap and stack (without needing to increase the value of [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwin5.html#​himem|HIMEM]]).   * Free heap/stack: the amount of memory available for growth of the heap and stack (without needing to increase the value of [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwin5.html#​himem|HIMEM]]).
 \\  In each case the memory size is given in bytes. Note that in normal circumstances **heap** usage will never decrease (there are exceptions such as use of the [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwin4.html#​clear|CLEAR]] statement, or deallocating a string at the top of the heap) but **stack** usage will increase and decrease, often by a considerable amount.\\ \\  The **PROCmonitor** routine is listed below. Note that it automatically loads the **WINLIB2** library if required, but doesn'​t do so if it is already installed:​\\ \\  \\  In each case the memory size is given in bytes. Note that in normal circumstances **heap** usage will never decrease (there are exceptions such as use of the [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwin4.html#​clear|CLEAR]] statement, or deallocating a string at the top of the heap) but **stack** usage will increase and decrease, often by a considerable amount.\\ \\  The **PROCmonitor** routine is listed below. Note that it automatically loads the **WINLIB2** library if required, but doesn'​t do so if it is already installed:​\\ \\ 
 +<code bb4w>
         DEF PROCmonitor         DEF PROCmonitor
         PRIVATE D%, L%         PRIVATE D%, L%
Line 50: Line 53:
         L% = FALSE         L% = FALSE
         ENDPROC         ENDPROC
 +</​code>​
memory_20usage_20monitor.txt ยท Last modified: 2018/04/17 17:45 by tbest3112