Richard Russell wrote: ↑Sat 21 Dec 2024, 12:11
There's less variation than with the 'pathological' case, but
ARM BASIC 5 and
Matrix Brandy stand out as using a surprising amount of memory compared with the rest.
When you consider that two 255-character strings will require 510 bytes of storage, plus the memory required to hold the variable references themselves, the fact that the majority of BBC BASIC versions only use a total of a Kilobyte or so of heap when running this program really isn't too bad at all, considering there is no traditional 'garbage collection'.
The old BBC BASIC (Z80) v2.20 isn't quite as good, at around 2 Kilobytes (v5.00 is much better), and both ARM BASIC 5 and Matrix Brandy are really rather poor at around 8 Kilobytes.
It's instructive to see what happens if you
initialise the strings to their maximum possible length, which is a strategy that was recommended with the old (1980s) 8-bit versions in order to minimise the use of string memory:
Code: Select all
10 S% = RND(-1234)
20 DIM A% -1
22 A$ = STRING$(255, "A")
24 B$ = STRING$(255, "B")
30 FOR I% = 1 TO 1000
40 A$ = STRING$(RND AND 255, "A")
50 B$ = STRING$(RND AND 255, "B")
60 NEXT I%
70 DIM B% -1
80 PRINT "Total memory used = "; B%-A%; " bytes"
Now the results are somewhat different:
- 6502 BASIC 2 (BeebEm): 526 bytes
- 6502 BASIC 4 (BeebEm): 526 bytes
- ARM BASIC 5 (RedSquirrel): 8124 bytes
- BBC BASIC (86) for MS-DOS v4.81†: 544 bytes
- Matrix Brandy v1.23.4 (Windows): 8392 bytes
- BBC BASIC for Windows v6.15a: 1130 bytes
- BBC BASIC for SDL 2.0 v1.40a 32-bit: 1130 bytes
- BBC BASIC for SDL 2.0 v1.40a 64-bit: 1246 bytes
- BBC BASIC (Z80) v2.20: 526 bytes
- BBC BASIC (Z80) v5.00: 526 bytes
† Large memory model version ('BIGBASIC')
Here there seem to be three distinct groups: the old 8-bit versions (6502 and Z80) all use 526 bytes, my 'modern' versions (BB4W and BBCSDL) around a Kilobyte, and once again the outliers are ARM BASIC 5 and Brandy BASIC at around 8 Kbytes.