This is an old revision of the document!
=====Fitting programs in the demo version===== //by Richard Russell, June 2007 amended January 2014//\\ \\ **//This article applies to BBC BASIC for Windows version 5.95a or later only //**\\ \\ The trial (evaluation) version of //BBC BASIC for Windows// provides, by default, 16 Kbytes (16384 bytes) //below// [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin5.html#himem|HIMEM]] for the user's program, variables (heap) and stack **plus** 8 Kbytes (8192 bytes) //above// [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin5.html#himem|HIMEM]] for [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin5.html#install|INSTALLed]] libraries or program modules executed using [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin4.html#callstring|CALL]]. Because there is an overhead of 256 bytes for each INSTALLed file, this means that a library file no bigger than 7936 bytes will load successfully in the default configuration; the majority of supplied libraries are smaller than this.\\ \\ If your program will not fit within the default memory provided in the demo version there are a number of strategies that may be applied in an attempt to make it do so.\\ \\ ==== Raising HIMEM ==== \\ If your program (plus its heap and stack space) requires more than the 16K available, but it doesn't INSTALL any libraries or CALL any external code modules, then you can raise HIMEM up to a maximum of 24 Kbytes above [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin6.html#page|PAGE]]. To ensure compatibility with the full version of BBC BASIC for Windows you should do this only when necessary:\\ \\ IF HIMEM<=PAGE+24576 THEN HIMEM=PAGE+24576 If you need some space above HIMEM, but less than the 8K provided by default, you can still raise HIMEM but to a lesser extent. For example if you need to INSTALL the **FNUSING** library, which requires less than 2K (including the 256 byte overhead), then you can raise HIMEM as follows:\\ \\ IF HIMEM<=PAGE+24576 THEN HIMEM=PAGE+22528 INSTALL @lib$+"FNUSING" \\ ==== Allocating memory from Windows ==== \\ If your program uses large arrays or blocks of data consider allocating the memory using the Windows API rather than from the heap. For example suppose you need a 10K block of data, which you would normally allocate from the heap as follows:\\ \\ DIM block% 10240-1 If there is insufficient room to do this with the demo version you can alternatively allocate the memory from Windows as follows:\\ \\ SYS "GlobalAlloc", 64, 10240 TO block% Remember that you must explicitly free memory allocated this way when you have finished with it:\\ \\ SYS "GlobalFree", block% If you want to declare an array, but there is insufficient room on the heap, you can use the method described in the article [[/Allocating%20arrays%20using%20the%20Windows%20API|Allocating arrays using the Windows API]]. For example suppose you would like to declare an array as follows:\\ \\ DIM array%(1000) If there is insufficient room to do this with the demo version you can allocate the memory from Windows as follows:\\ \\ PROCdim1d(array%(), 4, 1000) \\ ==== Other techniques ==== \\ Using short variable/function names, omitting unnecessary spaces and limiting comments will obviously help a program to fit in a restricted memory space, but are undesirable if the clarity of the program suffers. Using [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin5.html#local|LOCAL]] arrays and structures rather than global ones, where possible, will help limit memory usage.\\ \\ You may find it helpful to incorporate the [[/Memory%20usage%20monitor|Memory usage monitor]] to give you an idea of how the memory is being used (if you use the [[/Tools%20and%20Utilities|Add-In Utility]] version it won't use up any more of your precious memory!).