Managed vs. unmanaged memory

for discussion of bbc basic for windows/sdl, brandy and more
Post Reply
Deleted User 9295

Managed vs. unmanaged memory

Post by Deleted User 9295 »

BBC BASIC supports two quite different mechanisms for handling memory (i.e. RAM): managed memory objects and unmanaged memory objects.

Unmanaged memory objects are blocks of RAM allocated from the heap or stack (using DIM or DIM ... LOCAL respectively) and represented by a raw pointer. Once allocated, the memory is typically accessed using indirection. For example:

Code: Select all

      DIM mem%% 999
      mem%%?456 = 123
If you attempt to access a location outside the range of memory allocated (e.g. mem%%?1000) BASIC can't detect this and it is likely to result in a catastrophic crash. Also, you must use a 64-bit pointer to ensure compatibility with 64-bit editions of BBC BASIC.

Managed memory objects are strings, arrays and (in some versions) structures, allocated from the heap or stack and represented by a name. They are 'understood' by BASIC and accessed using a dedicated syntax for the relevant data type. For example:

Code: Select all

      DIM mem&(999)
      mem&(456) = 123
If you attempt to access a location outside the range of memory allocated (e.g. mem&(1000)) BASIC will detect this and report an error, in this case 'Subscript out of range'. The code typically will not need to be altered to achieve 64-bit compatibility.

From my perspective, programs written today should never (or only in exceptional circumstances) use unmanaged memory, they should always use strings, arrays and structures in preference. This will result in programs that are more 'resilient' and less likely to need modification to run on a range of different platforms.
Post Reply

Return to “modern implementations of classic programming languages”