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.
Dependents: mbed_cdc_hid_composite
Fork of USBDevice by
Diff: USBSerial/CircBuffer.h
- Revision:
- 51:deafa44182d9
- Parent:
- 14:d495202c90f4
--- 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
