14 key(0), dataPtr(nullptr), numOfElements(0)
42 if (index < numOfElements) {
43 return dataPtr[index];
45 throw std::out_of_range(
"yarp::dev::impl::Buffer::getValue(index): index is out of range");
53 if (index < numOfElements) {
54 dataPtr[index] = value;
56 throw std::out_of_range(
"yarp::dev::impl::Buffer::setValue(index, value): index is out of range");
64 return dataPtr[index];
71 m_numElem = zizeOfBuffers;
74 for (
size_t i = 0; i < initialNumOfBuffers; i++) {
75 T* buff =
new T[m_numElem];
76 m_buffers.push_back(buff);
78 m_usedBuffers.resize(initialNumOfBuffers,
false);
91 bool needNewBuff =
true;
92 if (
false == m_usedBuffers[m_firstFreeBuff]) {
97 for (std::size_t p = 0; p < m_buffers.size(); p++) {
98 if (
false == m_usedBuffers[p]) {
109 dataPtr =
new T[m_numElem];
110 if (
nullptr == dataPtr) {
112 yError() <<
"FixedSizeBuffersManager::getBuffer() no more memory!!";
114 m_buffers.push_back(dataPtr);
115 m_usedBuffers.push_back(
true);
117 i = m_buffers.size() - 1;
122 dataPtr = m_buffers[i];
123 m_usedBuffers[i] =
true;
157 if (
buffer.key >= m_buffers.size()) {
158 yError() <<
"FixedSizeBuffersManager::releaseBuffer((Buffer<T> &buffer) error in deallocation!!";
161 m_usedBuffers[
buffer.key] =
false;
162 m_firstFreeBuff =
buffer.key;
172 for (std::size_t i = 0; i < m_buffers.size(); i++) {
173 yDebug() <<
"buff[" << i <<
"]: addr = " << m_buffers[i] <<
"; it is used?" << m_usedBuffers[i];
183 for (
size_t i = 0; i < m_buffers.size(); i++) {
184 delete[] m_buffers[i];
Buffer contains info about a buffer of type T and it is used to exchange information with yarp::dev::...
T * getData()
Return the data pointer.
~Buffer()
Destructor.Note that the memory will not deallocated.
T & operator[](uint32_t index)
Access specified element.
T getValue(uint32_t index)
Return the value contained in the buffer at index index.
uint32_t getSize()
Return the number of element of buffer.
void setValue(uint32_t index, T value)
Set the value @value in the buffer at index index.
FixedSizeBuffersManager(uint32_t sizeOfBuffers, std::size_t initialNumOfBuffers=3)
Constructor.
void printBuffers()
Prints info of buffers.
std::size_t getBufferSize()
Get the number of elements of a buffer.
Buffer< T > getBuffer()
Get a buffer and fill its information in @buffer.
void releaseBuffer(Buffer< T > &buffer)
Release a buffer.
~FixedSizeBuffersManager()
Destructor.