Buffer from Sam Grove changed to have static instead of dynamic memory allocation. Fixed size to 256B.
Dependents: BufferedSerialStatic
Fork of Buffer by
Revision 2:d13a72146516, committed 2013-05-23
- Comitter:
- sam_grove
- Date:
- Thu May 23 23:48:36 2013 +0000
- Parent:
- 1:490224f41c09
- Child:
- 4:cd0a1f4c623f
- Commit message:
- Optimized the use of _size and created _sizemask instead. Faster during normal operation.
Changed in this revision
Buffer.cpp | Show annotated file Show diff for this revision Revisions of this file |
Buffer.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Buffer.cpp Thu May 23 19:26:31 2013 +0000 +++ b/Buffer.cpp Thu May 23 23:48:36 2013 +0000 @@ -27,7 +27,7 @@ Buffer<T>::Buffer(BUFFER_SIZE size) { _buf = new T [size]; - _size = size; + _sizemask = size-1; clear(); return; @@ -45,7 +45,7 @@ void Buffer<T>::put(T data) { _buf[_wloc++] = data; - _wloc &= (_size-1); + _wloc &= _sizemask; return; } @@ -54,7 +54,7 @@ T Buffer<T>::get(void) { T data_pos = _buf[_rloc++]; - _rloc &= (_size-1); + _rloc &= _sizemask; return data_pos; } @@ -72,7 +72,7 @@ { _wloc = 0; _rloc = 0; - memset(_buf, 0, _size); + memset(_buf, 0, _sizemask+1); return; } @@ -83,6 +83,14 @@ return (_wloc == _rloc) ? 0 : 1; } +template <class T> +uint32_t Buffer<T>::peek(char c) +{ + return 1; +} + + + // make the linker aware of some possible types template class Buffer<uint8_t>; template class Buffer<int8_t>;
--- a/Buffer.h Thu May 23 19:26:31 2013 +0000 +++ b/Buffer.h Thu May 23 23:48:36 2013 +0000 @@ -64,7 +64,7 @@ T *_buf; volatile uint32_t _wloc; volatile uint32_t _rloc; - uint32_t _size; + uint32_t _sizemask; enum BUFFER_SIZE{SMALL = 0x100, MEDIUM = 0x400, LARGE = 0x1000}; @@ -120,6 +120,8 @@ return get(); } + uint32_t peek(char c); + }; #endif