User Tools

Site Tools


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 HIMEM for the user's program, variables (heap) and stack plus 8 Kbytes (8192 bytes) above HIMEM for INSTALLed libraries or program modules executed using 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 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 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 LOCAL arrays and structures rather than global ones, where possible, will help limit memory usage.

You may find it helpful to incorporate the Memory usage monitor to give you an idea of how the memory is being used (if you use the Add-In Utility version it won't use up any more of your precious memory!).

This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information
fitting_20programs_20in_20the_20demo_20version.txt · Last modified: 2018/04/17 17:16 by tbest3112