Proposal for a 'listlib' library

Discussions related to the code libraries supplied with BB4W & BBCSDL
User avatar
hellomike
Posts: 194
Joined: Sat 09 Jun 2018, 09:47
Location: Amsterdam

Re: Proposal for a 'listlib' library

Post by hellomike »

Very useful Richard.
Will you include this new library in future BBCSDL and BB4W releases?
Richard Russell
Posts: 457
Joined: Tue 18 Jun 2024, 09:32

Re: Proposal for a 'listlib' library

Post by Richard Russell »

hellomike wrote: Sun 27 Jul 2025, 13:22 Will you include this new library in future BBCSDL and BB4W releases?
Currently the listlib library is BBCSDL only (it's not compatible with BB4W because of calling SDL2 memory-management functions). In principle a BB4W version could be produced, but that's not something I've given any serious thought to.

In any case, new releases of BB4W are so infrequent - it's entirely possible that there won't be any more - that should a BB4W version of the library be developed it would probably best be made available another way (e.g. by direct download).

There's also the complication of the Console Mode editions of BBC BASIC (BBCTTY) because they would need yet another version of the library, for the same reason (memory management functions).

One approach would be to develop a 'universal' library which detects which version of BBC BASIC it is running on and uses the appropriate functions for that platform. But that could add a run-time overhead because of the version-testing code, and hit performance.

Another approach would be to adopt the technique I used in the classlib library, which is not to call OS memory-management functions at all but to leverage BBC BASIC's built-in string-management functions. But that would limit the size of list to what fits in BBC BASIC's heap.

I'm open to suggestions. Perhaps the most practical approach is to be led by demand: if nobody expresses any interest in using the library - and they haven't so far - it's all moot! :)
Richard Russell
Posts: 457
Joined: Tue 18 Jun 2024, 09:32

Re: Proposal for a 'listlib' library

Post by Richard Russell »

Richard Russell wrote: Sun 27 Jul 2025, 14:57 Another approach would be to adopt the technique I used in the classlib library, which is not to call OS memory-management functions at all but to leverage BBC BASIC's built-in string-management functions. But that would limit the size of list to what fits in BBC BASIC's heap.
Yet another approach would be to adopt the technique I used in gpiolib.bbc which is to point a function at a different function, so that thereafter that alternative function is called instead. Here's how it's used in gpiolib:

Code: Select all

        PTR(PROC_gpio_inp()) = PTR(PROC_gpio_inp_5())
The potential advantage is that the overhead of testing the current platform happens only on the first call; thereafter no further tests are required and it's as fast as a dedicated library for the current platform would be.
Richard Russell
Posts: 457
Joined: Tue 18 Jun 2024, 09:32

Re: Proposal for a 'listlib' library

Post by Richard Russell »

Richard Russell wrote: Sun 27 Jul 2025, 20:12 Yet another approach would be to adopt the technique I used in gpiolib.bbc which is to point a function at a different function, so that thereafter that alternative function is called instead.
This is what that looks like in practice, when applied to listlib:

Code: Select all

 1890 DEF PROC_listredim(RETURN l%%,D%)
 1900 CASE TRUE OF
 1910   WHEN INKEY(-256)=&57:   PTR(PROC_listredim()) = PTR(PROC_listredim_win())
 1920   WHEN (@platform%>>8)=0: PTR(PROC_listredim()) = PTR(PROC_listredim_tty())
 1930   OTHERWISE:              PTR(PROC_listredim()) = PTR(PROC_listredim_sdl())
 1940 ENDCASE
 1950 PROC_listredim(l%%,D%)
 1960 ENDPROC
Superficially this looks like an example of a recursive doom-loop, with the procedure forever calling itself in line 1950 until it eventually runs out of memory. But that's not what happens, because before it reaches line 1950 it has modified the procedure's pointer so the PROC_listredim is not a recursive call after all!
User avatar
hellomike
Posts: 194
Joined: Sat 09 Jun 2018, 09:47
Location: Amsterdam

Re: Proposal for a 'listlib' library

Post by hellomike »

I fully understand your reasoning about BB4W and therefor I'm fine with a direct download.
Also, I wouldn't mind in having a go converting the BBCSDL one myself into using Windows memory-management functions.