13 #define RINGBUF_BURST_XFER 1 26 _dyna = (buf != NULL);
49 *Data = *(_buffer + _tail);
50 if (++_tail >= _size) _tail = 0;
61 *(_buffer + _head) = Data;
62 if (++_head >= _size) _head = 0;
63 if (_head == _tail) _full =
true;
68 #if !RINGBUF_BURST_XFER // One by one slug transfer... 72 bool ok = (
Unused() >= Count);
74 while( Count-- )
Put( *Data++ );
81 bool ok = (
Used() >= Count);
84 while( Count-- )
Get( Data++ );
89 #else // Burst transfer - Beta 93 bool ok = (
Unused() >= Count);
96 if (_head + Count <= _size)
98 memcpy( _buffer + _head, Data, Count );
103 UINT nfirst = _size - _head;
104 UINT nsecond = Count - nfirst;
105 if ( nfirst ) memcpy( _buffer + _head, Data, nfirst );
106 if ( nsecond ) memcpy( _buffer, Data + nfirst, nsecond );
109 IF_DEBUG(
if (_head > _size) __debugbreak() );
110 if (_head == _size) _head = 0;
111 int diff = _head - _tail;
112 if (diff < 0) diff += _size;
113 if (!diff || (diff == (
int)_size)) _full =
true;
120 bool ok = (
Used() >= Count);
123 if (_tail + Count <= _size)
125 memcpy( Data, _buffer + _tail, Count );
130 UINT nfirst = _size - _tail;
131 UINT nsecond = Count - nfirst;
132 if ( nfirst ) memcpy( Data, _buffer + _tail, nfirst );
133 if ( nsecond ) memcpy( Data + nfirst, _buffer, nsecond );
136 IF_DEBUG(
if (_tail > _size) __debugbreak() );
137 if (_tail == _size) _tail = 0;
143 #endif // RINGBUF_BURST_XFER 150 while( *(_buffer + offs) != 0 )
153 if (++offs >= _size) offs = 0;
154 if (offs == start)
return false;
157 bool ok = (BufSize >= strLen);
162 Buf[ BufSize-1 ] = 0;
171 bool counted = (StrLen != 0);
172 if (!counted) StrLen = (UINT) strlen( Str );
173 bool ok = (
Unused() > StrLen);
176 UINT length = counted ? StrLen : StrLen+1;
178 if (counted && (Str[ length-1 ] != 0))
Put( 0 );
194 if (Count >= avail)
Clear();
206 if ( _full )
return _size;
207 INT count = _head - _tail;
208 if (count < 0) count += _size;
214 return _size -
Used();
219 return ((_tail == _head) && !_full);
227 RaiseException( EXCEPTION_ARRAY_BOUNDS_EXCEEDED, 0, 0, NULL );
229 ULONG_PTR info[ 2 ] = { (ULONG_PTR)
this, Index };
235 return _buffer[ Index ];
void Attach(PBYTE Array, UINT Size)
BYTE & operator[](UINT Index)
bool GetStr(ASTR Buf, UINT BufLen)
void * mem_Alloc(size_t Bytes)
bool PutBlock(BYTE *Data, UINT nBytes)
bool PutStr(ACSTR Str, UINT Len=0)
RingBuffer(PBYTE Array, UINT Size)
void * mem_Free(void *pBlk)
Debug and error handling support.
bool GetBlock(BYTE *Data, UINT nBytes)
#define EXCEPTION_RINGBUFFER_INVALID_INDEX
void Discard(UINT nBytes)