Safe API Framework
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
Buffer Module - Architecture

View-Based Buffer Design

  • Buffer is a lightweight VIEW over caller-owned storage. No allocation,
  • no freeing - just state tracking: data pointer, capacity, current length.

Core API

  • * sapi_buffer_init(buf, storage, capacity); // Bind view to storage
    * sapi_buffer_set_length(buf, new_length); // Mark data as valid
    * sapi_buffer_clear(buf); // Reset length to 0
    *

Invariants

  •  * buf.data != NULL           - Pointing to valid storage
     * buf.capacity > 0           - Has space
     * buf.length <= buf.capacity - Never overfilled
     * 

Ownership Model

  • Caller owns backing storage:
  • - Must allocate before sapi_buffer_init()
  • - Must keep valid for buffer lifetime
  • - Caller manages writes to buf.data
  • Buffer manages:
  • - Tracking length (valid data)
  • - Validating length <= capacity

O(1) All Operations

  • | Operation | Time |
  • |--------—|---—|
  • | init() | O(1) |
  • | set_length() | O(1) |
  • | clear() | O(1) |
  • No copying, no allocation.

See Also