-
Notifications
You must be signed in to change notification settings - Fork 36
/
IGKCircularBuffer.h
45 lines (31 loc) · 1.59 KB
/
IGKCircularBuffer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
typedef struct {
// 0 <= elementCount <= actualSize <= targetSize
//The number of elements in the buffer
CFIndex elementCount;
//The amount of elements that we have allocated enough memory to hold. Must not be 0
CFIndex allocatedCount;
//The maximum number of elements that the buffer will grow to hold before it starts discarding things
CFIndex maximumCount;
//The size in bytes of each element in the buffer
CFIndex elementSize;
//A pointer to all the elements
void* items;
//The offset of the element that was added the longest time ago
CFIndex oldestElement;
//The offset of the element that was added most recently
CFIndex youngestElement;
} IGKCircularBuffer;
//Create a buffer and fill it with data
IGKCircularBuffer IGKCircularBufferCreateFromData(const void *data, CFIndex dataLength, CFIndex maximumCount, CFIndex elementSize);
//Create an empty buffer with a specified size
IGKCircularBuffer IGKCircularBufferCreate(CFIndex maximumCount, CFIndex elementSize, CFIndex initialSize);
//Add elementSize bytes of *pointerToData to the buffer.
void IGKCircularBufferAdd(IGKCircularBuffer buffer, void* pointerToData);
//Get a pointer to the raw data and the length of the data, eg to pass to NSData
void* IGKCircularBufferRawData(IGKCircularBuffer buffer);
CFIndex IGKCircularBufferRawDataLength(IGKCircularBuffer buffer);
//Get data in a format suitable for writing out to disk
NSData* IGKCircularBufferOrderedData(IGKCircularBuffer buffer);
CFIndex IGKCircularBufferOrderedDataLength(IGKCircularBuffer buffer);
//Delete the buffer
void IGKCircularBufferFree(IGKCircularBuffer buffer);