-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite.cpp
More file actions
33 lines (26 loc) · 879 Bytes
/
write.cpp
File metadata and controls
33 lines (26 loc) · 879 Bytes
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
#include "ringbuffer.h"
#include <stdio.h>
#include <iostream>
//测试程序:ringbuffer空间大小为10,存入15个数据,会造成5个数据被新数据覆盖而消失
//读的时候依然是从最早未被覆盖的数据开始读,仍然维持先进先出
int main(){
ringbuffer<int> ringbuffer(10);
int data[15];
for(int i = 0; i < 15; i++){
data[i] = i;
}
ringbuffer.write(data, 15);
for(int i = 0; i < 10; i++){
std::cout << ringbuffer.getNum(i) << std::endl;
}
int nums[10];
for(int i = 0; i < 10; i++){
ringbuffer.read(nums, 10);
}
std::cout << "读完后ringbuffer剩余数据数为:" << ringbuffer.getOccupied() << std::endl;
std::cout << "读出的数据依次为:" << std::endl;
for(int i = 0; i < 10; i++){
std::cout << nums[i] << std::endl;
}
return 0;
}