关于三缓存机制的使用
2017-08-31 09:37
246 查看
最近在做图像采集——》然后进入算法——》接着再显示到屏幕,这样就出现了问题,硬件不断的采集图像上传上来,然而算法的速度不够快,就出现 了问题。
如果只开辟一个内存来读取写入,那么,就只能给上锁,这样会降低效率。出现卡顿的情况
,还有一种问题就是采集慢,算法快也会出现卡顿。
所以就写了一个三缓存机制来应对。
triplebuf.h文件,也是核心文件是一个类模板
QQ:609162385获取源码。。或者在csdn资源中搜索“三缓存机制”下载资源
然后定义一个test.h的类来测试
#ifndef TEST_H
#define TEST_H
#include <QObject>
#include "triplebuff.h"
struct FrameStruc{
int fd_raw;
};
class test: public QObject
{
public:
test();
~test();
void add_foo();
private:
FrameStruc m_struct_frame[3]; // 三缓存区
SciPack::TripleTpl<FrameStruc*> m_triple_obj; // 三缓存对象
};
#endif // TEST_Htest.cpp
#include "test.h"
#include <thread>
#include <iostream>
#include <cassert>
#include <atomic>
#include <vector>
#include <unistd.h>
#include <QThread>
#include <sstream>
#include <QDebug>
void test::add_foo()
{
FrameStruc s;
s.fd_raw = 4;
FrameStruc* struc = ((&m_triple_obj)->readValue( ));//读取
qDebug()<<struc->fd_raw;//打印
(&m_triple_obj)->swap();//交换
struc = ((&m_triple_obj)->readValue( ));//读取
qDebug()<<struc->fd_raw;//打印
(&m_triple_obj)->swap();//交换
struc = ((&m_triple_obj)->readValue( ));//读取
qDebug()<<struc->fd_raw;//打印
(&m_triple_obj)->writeValue(&s);//写入
(&m_triple_obj)->swap();//交换
struc = ((&m_triple_obj)->readValue( ));//读取
qDebug()<<struc->fd_raw;//打印
(&m_triple_obj)->swap();//交换
struc = ((&m_triple_obj)->readValue( ));//读取
qDebug()<<struc->fd_raw;//打印
}
test::test():
m_triple_obj( & m_struct_frame[0], & m_struct_frame[1], & m_struct_frame[2] )
{
m_struct_frame[0].fd_raw = 1;
m_struct_frame[1].fd_raw = 2;
m_struct_frame[2].fd_raw = 3;
add_foo();
}
test::~test()
{
}
main.cpp
#include <QApplication>
#include "test.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
test sl;
return a.exec();
}
程序运行结果:
如果只开辟一个内存来读取写入,那么,就只能给上锁,这样会降低效率。出现卡顿的情况
,还有一种问题就是采集慢,算法快也会出现卡顿。
所以就写了一个三缓存机制来应对。
triplebuf.h文件,也是核心文件是一个类模板
QQ:609162385获取源码。。或者在csdn资源中搜索“三缓存机制”下载资源
然后定义一个test.h的类来测试
#ifndef TEST_H
#define TEST_H
#include <QObject>
#include "triplebuff.h"
struct FrameStruc{
int fd_raw;
};
class test: public QObject
{
public:
test();
~test();
void add_foo();
private:
FrameStruc m_struct_frame[3]; // 三缓存区
SciPack::TripleTpl<FrameStruc*> m_triple_obj; // 三缓存对象
};
#endif // TEST_Htest.cpp
#include "test.h"
#include <thread>
#include <iostream>
#include <cassert>
#include <atomic>
#include <vector>
#include <unistd.h>
#include <QThread>
#include <sstream>
#include <QDebug>
void test::add_foo()
{
FrameStruc s;
s.fd_raw = 4;
FrameStruc* struc = ((&m_triple_obj)->readValue( ));//读取
qDebug()<<struc->fd_raw;//打印
(&m_triple_obj)->swap();//交换
struc = ((&m_triple_obj)->readValue( ));//读取
qDebug()<<struc->fd_raw;//打印
(&m_triple_obj)->swap();//交换
struc = ((&m_triple_obj)->readValue( ));//读取
qDebug()<<struc->fd_raw;//打印
(&m_triple_obj)->writeValue(&s);//写入
(&m_triple_obj)->swap();//交换
struc = ((&m_triple_obj)->readValue( ));//读取
qDebug()<<struc->fd_raw;//打印
(&m_triple_obj)->swap();//交换
struc = ((&m_triple_obj)->readValue( ));//读取
qDebug()<<struc->fd_raw;//打印
}
test::test():
m_triple_obj( & m_struct_frame[0], & m_struct_frame[1], & m_struct_frame[2] )
{
m_struct_frame[0].fd_raw = 1;
m_struct_frame[1].fd_raw = 2;
m_struct_frame[2].fd_raw = 3;
add_foo();
}
test::~test()
{
}
main.cpp
#include <QApplication>
#include "test.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
test sl;
return a.exec();
}
程序运行结果:
相关文章推荐
- Android中关于Volley的使用(八)缓存机制的深入认识
- Android中关于Volley的使用(八)缓存机制的深入认识
- 关于listview中是用多个布局 并使用holderView 缓存机制的问题
- Android中关于Volley的使用(八)缓存机制的深入认识
- Android中关于Volley的使用(五)缓存机制的深入认识
- Android中关于Volley的使用(八)缓存机制的深入认识
- 关于iBatis的缓存使用
- 关于hibernate的缓存使用
- 关于hibernate的缓存使用
- 使用SqlCacheDependency的一点注记(如何开启Sqlserver2000的缓存机制)
- The NOTE of learning ASP.NET [19] 关于GC(内存回收机制)、对象的销毁和using的使用
- 关于hibernate的缓存使用
- 使用SqlCacheDependency的一点注记(如何开启Sqlserver2000的缓存机制)
- 关于hibernate的缓存使用
- TX电话面试:关于浏览器的缓存,请求机制
- 关于hibernate的缓存使用
- CYQ.Data 轻量数据层之路 V4.5 版本发布[更好的使用体验,更优的缓存机制]
- 关于hibernate的缓存使用
- JAVA Web 安全机制----使用filter验证session用户和页面缓存问题处理
- 关于hibernate的缓存使用(hibernate2)