EstervQrCode 1.1.1
Library for qr code manipulation
Public Types | Public Member Functions | Protected Attributes | List of all members
cv::AutoBuffer< _Tp, fixed_size > Class Template Reference

Automatically Allocated Buffer Class. More...

#include <utility.hpp>

Public Types

typedef _Tp value_type
 

Public Member Functions

 AutoBuffer ()
 the default constructor More...
 
 AutoBuffer (size_t _size)
 constructor taking the real buffer size More...
 
 AutoBuffer (const AutoBuffer< _Tp, fixed_size > &buf)
 the copy constructor More...
 
AutoBuffer< _Tp, fixed_size > & operator= (const AutoBuffer< _Tp, fixed_size > &buf)
 the assignment operator More...
 
 ~AutoBuffer ()
 destructor. calls deallocate() More...
 
void allocate (size_t _size)
 allocates the new buffer of size _size. if the _size is small enough, stack-allocated buffer is used More...
 
void deallocate ()
 deallocates the buffer if it was dynamically allocated More...
 
void resize (size_t _size)
 resizes the buffer and preserves the content More...
 
size_t size () const
 returns the current buffer size More...
 
_Tp * data ()
 returns pointer to the real buffer, stack-allocated or heap-allocated More...
 
const _Tp * data () const
 returns read-only pointer to the real buffer, stack-allocated or heap-allocated More...
 
 operator _Tp * ()
 returns pointer to the real buffer, stack-allocated or heap-allocated More...
 
 operator const _Tp * () const
 returns read-only pointer to the real buffer, stack-allocated or heap-allocated More...
 

Protected Attributes

_Tp * ptr
 pointer to the real buffer, can point to buf if the buffer is small enough More...
 
size_t sz
 size of the real buffer More...
 
_Tp buf [(fixed_size > 0) ? fixed_size :1]
 pre-allocated buffer. At least 1 element to confirm C++ standard requirements More...
 

Detailed Description

template<typename _Tp, size_t fixed_size = 1024/sizeof(_Tp)+8>
class cv::AutoBuffer< _Tp, fixed_size >

Automatically Allocated Buffer Class.

The class is used for temporary buffers in functions and methods. If a temporary buffer is usually small (a few K's of memory), but its size depends on the parameters, it makes sense to create a small fixed-size array on stack and use it if it's large enough. If the required buffer size is larger than the fixed size, another buffer of sufficient size is allocated dynamically and released after the processing. Therefore, in typical cases, when the buffer size is small, there is no overhead associated with malloc()/free(). At the same time, there is no limit on the size of processed data.

This is what AutoBuffer does. The template takes 2 parameters - type of the buffer elements and the number of stack-allocated elements. Here is how the class is used:

void my_func(const cv::Mat& m)
{
cv::AutoBuffer<float> buf(1000); // create automatic buffer containing 1000 floats
buf.allocate(m.rows); // if m.rows <= 1000, the pre-allocated buffer is used,
// otherwise the buffer of "m.rows" floats will be allocated
// dynamically and deallocated in cv::AutoBuffer destructor
...
}
Automatically Allocated Buffer Class.
Definition: utility.hpp:102
_Tp buf[(fixed_size > 0) ? fixed_size :1]
pre-allocated buffer. At least 1 element to confirm C++ standard requirements
Definition: utility.hpp:150
n-dimensional dense array class
Definition: mat.hpp:812
int rows
the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions
Definition: mat.hpp:2138

Member Typedef Documentation

◆ value_type

template<typename _Tp , size_t fixed_size = 1024/sizeof(_Tp)+8>
typedef _Tp cv::AutoBuffer< _Tp, fixed_size >::value_type

Constructor & Destructor Documentation

◆ AutoBuffer() [1/3]

template<typename _Tp , size_t fixed_size = 1024/sizeof(_Tp)+8>
cv::AutoBuffer< _Tp, fixed_size >::AutoBuffer ( )

the default constructor

◆ AutoBuffer() [2/3]

template<typename _Tp , size_t fixed_size = 1024/sizeof(_Tp)+8>
cv::AutoBuffer< _Tp, fixed_size >::AutoBuffer ( size_t  _size)
explicit

constructor taking the real buffer size

◆ AutoBuffer() [3/3]

template<typename _Tp , size_t fixed_size = 1024/sizeof(_Tp)+8>
cv::AutoBuffer< _Tp, fixed_size >::AutoBuffer ( const AutoBuffer< _Tp, fixed_size > &  buf)

the copy constructor

◆ ~AutoBuffer()

template<typename _Tp , size_t fixed_size = 1024/sizeof(_Tp)+8>
cv::AutoBuffer< _Tp, fixed_size >::~AutoBuffer ( )

destructor. calls deallocate()

Member Function Documentation

◆ allocate()

template<typename _Tp , size_t fixed_size = 1024/sizeof(_Tp)+8>
void cv::AutoBuffer< _Tp, fixed_size >::allocate ( size_t  _size)

allocates the new buffer of size _size. if the _size is small enough, stack-allocated buffer is used

◆ data() [1/2]

template<typename _Tp , size_t fixed_size = 1024/sizeof(_Tp)+8>
_Tp* cv::AutoBuffer< _Tp, fixed_size >::data ( )
inline

returns pointer to the real buffer, stack-allocated or heap-allocated

◆ data() [2/2]

template<typename _Tp , size_t fixed_size = 1024/sizeof(_Tp)+8>
const _Tp* cv::AutoBuffer< _Tp, fixed_size >::data ( ) const
inline

returns read-only pointer to the real buffer, stack-allocated or heap-allocated

◆ deallocate()

template<typename _Tp , size_t fixed_size = 1024/sizeof(_Tp)+8>
void cv::AutoBuffer< _Tp, fixed_size >::deallocate ( )

deallocates the buffer if it was dynamically allocated

◆ operator _Tp *()

template<typename _Tp , size_t fixed_size = 1024/sizeof(_Tp)+8>
cv::AutoBuffer< _Tp, fixed_size >::operator _Tp * ( )
inline

returns pointer to the real buffer, stack-allocated or heap-allocated

◆ operator const _Tp *()

template<typename _Tp , size_t fixed_size = 1024/sizeof(_Tp)+8>
cv::AutoBuffer< _Tp, fixed_size >::operator const _Tp * ( ) const
inline

returns read-only pointer to the real buffer, stack-allocated or heap-allocated

◆ operator=()

template<typename _Tp , size_t fixed_size = 1024/sizeof(_Tp)+8>
AutoBuffer<_Tp, fixed_size>& cv::AutoBuffer< _Tp, fixed_size >::operator= ( const AutoBuffer< _Tp, fixed_size > &  buf)

the assignment operator

◆ resize()

template<typename _Tp , size_t fixed_size = 1024/sizeof(_Tp)+8>
void cv::AutoBuffer< _Tp, fixed_size >::resize ( size_t  _size)

resizes the buffer and preserves the content

◆ size()

template<typename _Tp , size_t fixed_size = 1024/sizeof(_Tp)+8>
size_t cv::AutoBuffer< _Tp, fixed_size >::size ( ) const

returns the current buffer size

Member Data Documentation

◆ buf

template<typename _Tp , size_t fixed_size = 1024/sizeof(_Tp)+8>
_Tp cv::AutoBuffer< _Tp, fixed_size >::buf[(fixed_size > 0) ? fixed_size :1]
protected

pre-allocated buffer. At least 1 element to confirm C++ standard requirements

◆ ptr

template<typename _Tp , size_t fixed_size = 1024/sizeof(_Tp)+8>
_Tp* cv::AutoBuffer< _Tp, fixed_size >::ptr
protected

pointer to the real buffer, can point to buf if the buffer is small enough

◆ sz

template<typename _Tp , size_t fixed_size = 1024/sizeof(_Tp)+8>
size_t cv::AutoBuffer< _Tp, fixed_size >::sz
protected

size of the real buffer


The documentation for this class was generated from the following file: