bufferwrite

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - File handling
Introduced first in SolidGeometry 1.0, Creation date: 2012-12-02, Last change: 2025-09-14

fills a buffer with byte oriented data

Description

this procedure fills a buffer with data and increments the size if required. The procedure is useful for generating encoded data before writing it into a file.

Example Illustration

 missing image of bufferwrite(B,p,data)

Syntax

[B,p]=bufferwrite(B,p,[data])

Input Parameter

B: Buffer
p: Pointer to last used byte
data: Byte oriented Data

Output Parameter

B: Buffer
p: Pointer to last used byte




Copyright 2012-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

This algorithm is designed to fill a buffer with byte-oriented data, expanding the buffer size if necessary. It is useful for preparing encoded data before writing it to a file.

Input Parameters

Output Results

Algorithm Steps

  1. Set a constant blocksize to 16, which determines the increment size for the buffer.
  2. Iterate over each data input provided in varargin (all inputs after the first two).
  3. For each data input:
    1. Check if the current buffer size is sufficient to hold the new data. If not, increase the buffer size by blocksize bytes.
    2. Initialize a new buffer NB with the increased size and copy the existing buffer content into it.
    3. Assign the new buffer NB back to B.
    4. Check if the data is of type 'uint8' or 'char'. If not, issue a warning indicating the data type is not as expected.
    5. Copy the data into the buffer starting from the position indicated by p.
    6. Update the pointer p to reflect the new end position of the data in the buffer.
Algorithm explaination created using ChatGPT on 2025-08-19 00:05. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21