buffer.cpp
来自「用于仿真系统中多个仿真对象间的内存管理」· C++ 代码 · 共 73 行
CPP
73 行
// Buffer.cpp: implementation of the Buffer class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Buffer.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Buffer::Buffer(long size,long thresh,MemoryPool* pool):
refCount(1)
{
datapoint = 0;
datahead = 0;
bufsize = size;
if(size > thresh)
{
strategy = new DataStrategy(pool);
}else
{
strategy = new MsgStrategy(pool);
}
}
Buffer::~Buffer()
{
delete strategy;
}
Buffer::Buffer(const Buffer& rhs)
{
}
float* Buffer::GetDataBuf()
{
if(datahead != 0)//已分配内存
return datahead;
datapoint = strategy->GetMemFromPool();
datahead = datapoint;
return datapoint;
}
void Buffer::AddReference()
{
++refCount;
}
void Buffer::ReleaseReference()
{
if(--refCount == 0)
{
strategy->ReturnMemToPool(datahead);
delete this;
}
}
float Buffer::ReadSample()
{
float sample = *datapoint;
datapoint++;
return sample;
}
void Buffer::WriteSample(float sample)
{
*datapoint = sample;
datapoint++;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?