USB device stack
Dependents: MATSU-bed_blinky MATSU-bed_detection
Fork of USBDevice by
Diff: USBSerial/CircBuffer.h
- Revision:
- 51:deafa44182d9
- Parent:
- 14:d495202c90f4
- Child:
- 56:151ba33713ff
diff -r a3c50882f2c5 -r deafa44182d9 USBSerial/CircBuffer.h --- a/USBSerial/CircBuffer.h Mon Apr 20 10:45:54 2015 +0100 +++ b/USBSerial/CircBuffer.h Thu Apr 23 08:45:28 2015 +0100 @@ -19,20 +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() { - free(buf); - } - + CircBuffer():write(0), read(0){} bool isFull() { return ((write + 1) % size == read); }; @@ -66,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]; }; #endif