Page 1 of 1

Stage 110-112: buffer type revisited

Posted: Fri Jun 30, 2023 1:00 pm
by frank
A buffer type was introduced last year, but it was limited to access by pointer. Some features have been added to make it easier and more flexible to work with buffers as placeholders for data:

- the function cbuf copies data types to a buffer.

Code: Select all

buffer = cbuf(string)
whereby an optional parameter can set a specific offset into the buffer:

Code: Select all

buffer = cbuf(string, 20)
- the routine clbuf clears a buffer:

Code: Select all

clbuf(buffer)
whereby an optional parameter can set a specific character to fill the buffer (the default is space, ascii character 32)

Code: Select all

clbuf(buffer, 45)
Manipulating buffers are important as the buffer type can be used as a record element:

Code: Select all

record device is
  block_id: uint8;
  block_name: byte * 8;    ' buffer
  block_size: uint;
end
Examples of buffer datatypes are in the wiki.

The record as a user-defined type is currently being implemented. While in the process, the UDT struc is also being revisited. The major difference between records and structures in SharpBASIC is that records have a fixed length and cannot hold strings (not even fixed-length strings).