Arraylib updated

Discussions related to the code libraries supplied with BB4W & BBCSDL
Richard Russell
Posts: 692
Joined: Tue 18 Jun 2024, 09:32

Arraylib updated

Post by Richard Russell »

I've updated the arraylib library to include the following new procedure, which creates a one-dimensional numeric array (of any type) aliasing a block of memory:

Code: Select all

      PROC_arrayalias(a(), p%%, N%)
On return the array a() will point to the block of memory starting at address p%% with length N% elements (so for example in the case of an integer array the size of the memory block would be N% * 4 bytes).

You can use this procedure to create two arrays which reference the same memory, for example:

Code: Select all

      DIM one%(9)
      PROC_arrayalias(two&(), ^one%(0), 40)
Now one%() and two&() reference the same 40 bytes of data.

You can also use it to alias an array in a structure, useful if you want to apply one of the whole array operations to it, which you usually can't do:

Code: Select all

      DIM struct{array%(4)}
      PROC_arrayalias(temp%(), ^struct.array%(0), 5)
      PRINT SUM(temp%())
As a new release of BBC BASIC for SDL 2.0 in unlikely in the foreseeable future you can grab a copy of the library directly from GitHub.