OpenCV 5.0.0
Open Source Computer Vision
Loading...
Searching...
No Matches
cv::AutoBuffer< _Tp, fixed_size > Class Template Reference

Automatically Allocated Buffer Class. More...

#include <opencv2/core/utility.hpp>

Public Types

typedef const _Tpconst_iterator
typedef const _Tpconst_reference
typedef std::ptrdiff_t difference_type
typedef _Tpiterator
typedef _Tpreference
typedef std::size_t size_type
typedef _Tp value_type

Public Member Functions

 AutoBuffer ()
 the default constructor
 AutoBuffer (const AutoBuffer< _Tp, fixed_size > &buf)
 the copy constructor
 AutoBuffer (size_t _size)
 constructor taking the real buffer size
 AutoBuffer (size_t _size, const _Tp &value)
 ~AutoBuffer ()
 destructor. calls deallocate()
void allocate (size_t _size)
 allocates the new buffer of size _size. if the _size is small enough, stack-allocated buffer is used
reference back ()
const_reference back () const
iterator begin ()
const_iterator begin () const
const_iterator cbegin () const
const_iterator cend () const
void clear ()
_Tpdata ()
 returns pointer to the real buffer, stack-allocated or heap-allocated
const _Tpdata () const
 returns read-only pointer to the real buffer, stack-allocated or heap-allocated
void deallocate ()
 deallocates the buffer if it was dynamically allocated
void emplace_back (_Tp &&value)
bool empty () const
iterator end ()
const_iterator end () const
reference front ()
const_reference front () const
 operator _Tp * ()
 returns pointer to the real buffer, stack-allocated or heap-allocated
 operator const _Tp * () const
 returns read-only pointer to the real buffer, stack-allocated or heap-allocated
AutoBuffer< _Tp, fixed_size > & operator= (const AutoBuffer< _Tp, fixed_size > &buf)
 the assignment operator
void pop_back ()
void push_back (_Tp &&value)
void push_back (const _Tp &value)
void resize (size_t _size)
 resizes the buffer and preserves the content
size_t size () const
 returns the current buffer size

Protected Attributes

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

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:175
Comma-separated Matrix Initializer.
Definition mat.hpp:964
int rows
the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions
Definition mat.hpp:2488

Member Typedef Documentation

◆ const_iterator

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

◆ const_reference

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

◆ difference_type

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

◆ iterator

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

◆ reference

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

◆ size_type

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

◆ 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/4]

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

the default constructor

◆ AutoBuffer() [2/4]

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/4]

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

◆ AutoBuffer() [4/4]

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

◆ back() [1/2]

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

◆ back() [2/2]

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

◆ begin() [1/2]

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

◆ begin() [2/2]

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

◆ cbegin()

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

◆ cend()

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

◆ clear()

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

◆ 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

◆ emplace_back()

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

◆ empty()

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

◆ end() [1/2]

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

◆ end() [2/2]

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

◆ front() [1/2]

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

◆ front() [2/2]

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

◆ 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

◆ pop_back()

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

◆ push_back() [1/2]

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

◆ push_back() [2/2]

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

◆ 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: