Update for new version of mbed.
Fork of USBDevice_STM32F103 by
Diff: USBSerial/CircBuffer.h
- Revision:
- 71:52ef20e36cab
- Parent:
- 65:48fe9050cb4a
diff -r c74dbe78ca5b -r 52ef20e36cab USBSerial/CircBuffer.h --- a/USBSerial/CircBuffer.h Sun Dec 03 21:14:26 2017 +0000 +++ b/USBSerial/CircBuffer.h Mon Dec 04 23:05:41 2017 +0000 @@ -19,16 +19,10 @@ #ifndef CIRCBUFFER_H #define CIRCBUFFER_H -template <class T> +template <class T, int Size> class CircBuffer { public: - CircBuffer(int length) { - write = 0; - read = 0; - size = length + 1; - buf = (T *)malloc(size * sizeof(T)); - }; - + CircBuffer():write(0), read(0){} bool isFull() { return ((write + 1) % size == read); }; @@ -62,8 +56,8 @@ private: volatile uint16_t write; volatile uint16_t read; - uint16_t size; - T * buf; + static const int size = Size+1; //a modern optimizer should be able to remove this so it uses no ram. + T buf[Size+1]; }; #endif