R_* :
+
  .      : 0   
  FILLED : 1
;

CYCLICAL_BUFFER >>
+
  QUEUE_RECORD >>
  +
    R_* Filled; PSTRUCT Pointer
  ;

  P_QUEUE_RECORD Array; INT From, To, Array_length
;

# // Queue < P_CYCLICAL_BUFFER 'Record_queue, INT Length > 
+
  Init (Record_queue, Length)
;

# // Reset < P_CYCLICAL_BUFFER '/Record_queue >
+
  Init (Record_queue, Record_queue->Array_length)
;

# // Init < P_CYCLICAL_BUFFER '/Record_queue, INT Length >
+
  # // FreeRecords <>
  +
    Record_queue->From, Record_queue->To = 0

    for Counter = 0; Counter < Record_queue->Array_length; Counter ++
    +
      Free (&Record_queue->Array[Counter].Pointer) [ Record_queue->Array[Counter].Pointer ]
    ;
  ;

  # // FreeMemory <>
  +    
    Free (&Record_queue->Array); Record_queue->Array_length = 0
  ;

  FreeRecords (), FreeMemory () [ Record_queue->Array ]

  Record_queue->Array = Allocate (&_, T_ARRAY, T_QUEUE_RECORD, Length, VM_WRITE_ZEROS)

  Record_queue->Array_length = Length
;

# // Length < P_CYCLICAL_BUFFER Record_queue > 
+
  return Abs (Record_queue->From - Record_queue->To)
;

# // IsEmpty < P_CYCLICAL_BUFFER Record_queue > *
+
  return 1 [ Record_queue->From = Record_queue->To ] | 0
;

# // AddTo < P_CYCLICAL_BUFFER '/Record_queue, T_* Record_type, ((PSTRUCT ') .) WriteData >
+
  # // SendPointer <>
  +
    Index = Record_queue->To

    Record_queue->Array[Index].Filled = R_FILLED

    Record_queue->Array[Index].Pointer = Allocate (&_, T_STRUCT, Record_type)

    WriteData (Record_queue->Array[Index].Pointer)
  ;

  # -> SendPointer <>
  +
    Index = Record_queue->To

    return . [ !Record_queue->Array[Index].Filled ] | ERR_ARENA_TRASHED
  ;

  if Record_queue->From = Record_queue->To
  +
    if Record_queue->To = Record_queue->Array_length - 1
    +
      Record_queue->To = 0; SendPointer ()
    ;
    else
    +
      Record_queue->To ++; SendPointer ()
    ;
  ;
  else
  +
    if Record_queue->From < Record_queue->To
    +
      if Record_queue->To = Record_queue->Array_length - 1
      +
        Record_queue->To = 0; SendPointer ()
      ;
      else
      +
        Record_queue->To ++; SendPointer ()
      ;
    ;
    else
    +
      if Record_queue->To = Record_queue->Array_length - 1
      +
        Error (ERR_BUFFER_OVERFLOW)
      ;
      else
      +
        Record_queue->To ++; SendPointer ()
      ;
    ;
  ;
;

# // TakeFrom < P_CYCLICAL_BUFFER '/Record_queue, ((PSTRUCT '/) .) ReadData >
+
  # // SendPointer <>
  +
    Index = Record_queue->From

    Record_queue->Array[Index].Filled = .

    ReadData (Record_queue->Array[Index].Pointer)

    Free (&Record_queue->Array[Index].Pointer)
  ;

  # -> SendPointer <>
  +
    Index = Record_queue->From

    return . [ Record_queue->Array[Index].Filled ] | ERR_ARENA_TRASHED
  ;

  if Record_queue->From = Record_queue->To
  +
    if Record_queue->From = Record_queue->Array_length - 1
    +
      Error (ERR_BUFFER_OVERFLOW)
    ;
    else
    +
      Error (ERR_BUFFER_OVERFLOW)
    ;
  ;
  else
  +
    if Record_queue->From < Record_queue->To
    +
      if Record_queue->From = Record_queue->Array_length - 1
      +
        Error (ERR_BUFFER_OVERFLOW)
      ;
      else
      +
        SendPointer (); Record_queue->From ++
      ;
    ;
    else
    +
      if Record_queue->From = Record_queue->Array_length - 1
      +
        SendPointer (); Record_queue->From = 0
      ;
      else
      +
        SendPointer (); Record_queue->From ++
      ;
    ;
  ;
;

