Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed 4DGL-uLCD-SE mbed-rtos nRF24L01P
Diff: CircularBuf.cpp
- Revision:
- 31:39d04aedc3e5
- Parent:
- 29:0c6f3c0c992a
- Child:
- 32:c40d581f50af
--- a/CircularBuf.cpp Mon Apr 23 15:04:28 2018 +0000 +++ b/CircularBuf.cpp Mon Apr 23 15:29:18 2018 +0000 @@ -2,13 +2,13 @@ #include "stdio.h" template <typename T> -CircularBuf<T>::CircularBuf(unsigned int size) : _size(size), _head(-1), _tail(-1) { - _data = new T[size]; +CircularBuf<T>::CircularBuf(unsigned int size) : _size(size), _head(size), _tail(size) { + _data = (T*)malloc(sizeof(T) * size); } template <typename T> CircularBuf<T>::~CircularBuf() { - delete _data; + free(_data); } template <typename T> @@ -39,23 +39,15 @@ for (int i = 0; i < size; i++) { unsigned int next = _tail + 1; - printf("Next %d\n\r", next); - if (next >= size) + if (next >= _size) { next = 0; + } - printf("Head %d\n\r", _head); - if (next == _head) + if (next > _head) return cnt; - printf("Tail %d\n\r", _tail); - printf("Cnt %d\n\r", cnt); - printf("Data[cnt] %d\n\r", data[cnt]); - printf("_Data[next] %d\n\r", _data[next]); - printf("&Data %x &_Data %x\n\r", data, &_data[0]); data[cnt] = _data[next]; _tail = next; - printf("Next %d\n\r", next); - printf("Tail %d\n\r", _tail); cnt++; }