OpenCV  2.4.13.7
Open Source Computer Vision
cv::AutoBuffer< _Tp, fixed_size > Class Template Reference

#include <core.hpp>

Public Types

enum  { buffer_padding = (int)((16 + sizeof(_Tp) - 1)/sizeof(_Tp)) }
 
typedef _Tp value_type
 

Public Member Functions

 AutoBuffer ()
 the default contructor More...
 
 AutoBuffer (size_t _size)
 constructor taking the real buffer size 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...
 
 operator _Tp * ()
 returns pointer to the real buffer, stack-allocated or head-allocated More...
 
 operator const _Tp * () const
 returns read-only pointer to the real buffer, stack-allocated or head-allocated More...
 
size_t getSize () const
 returns number of allocated elements More...
 

Protected Attributes

_Tp * ptr
 pointer to the real buffer, can point to buf if the buffer is small enough More...
 
size_t size
 size of the real buffer More...
 
_Tp buf [fixed_size+buffer_padding]
 pre-allocated buffer More...
 

Detailed Description

template<typename _Tp, size_t fixed_size = 4096/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, 1000> buf; // 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
...
}

Member Typedef Documentation

§ value_type

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

Member Enumeration Documentation

§ anonymous enum

template<typename _Tp, size_t fixed_size = 4096/sizeof(_Tp)+8>
anonymous enum
Enumerator
buffer_padding 

Constructor & Destructor Documentation

§ AutoBuffer() [1/2]

template<typename _Tp , size_t fixed_size>
cv::AutoBuffer< _Tp, fixed_size >::AutoBuffer ( )
inline

the default contructor

§ AutoBuffer() [2/2]

template<typename _Tp , size_t fixed_size>
cv::AutoBuffer< _Tp, fixed_size >::AutoBuffer ( size_t  _size)
inline

constructor taking the real buffer size

§ ~AutoBuffer()

template<typename _Tp , size_t fixed_size>
cv::AutoBuffer< _Tp, fixed_size >::~AutoBuffer ( )
inline

destructor. calls deallocate()

Member Function Documentation

§ allocate()

template<typename _Tp , size_t fixed_size>
void cv::AutoBuffer< _Tp, fixed_size >::allocate ( size_t  _size)
inline

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

§ deallocate()

template<typename _Tp , size_t fixed_size>
void cv::AutoBuffer< _Tp, fixed_size >::deallocate ( )
inline

deallocates the buffer if it was dynamically allocated

§ getSize()

template<typename _Tp , size_t fixed_size>
size_t cv::AutoBuffer< _Tp, fixed_size >::getSize ( ) const
inline

returns number of allocated elements

§ operator _Tp *()

template<typename _Tp , size_t fixed_size>
cv::AutoBuffer< _Tp, fixed_size >::operator _Tp * ( )
inline

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

§ operator const _Tp *()

template<typename _Tp , size_t fixed_size>
cv::AutoBuffer< _Tp, fixed_size >::operator const _Tp * ( ) const
inline

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

Member Data Documentation

§ buf

template<typename _Tp, size_t fixed_size = 4096/sizeof(_Tp)+8>
_Tp cv::AutoBuffer< _Tp, fixed_size >::buf[fixed_size+buffer_padding]
protected

pre-allocated buffer

§ ptr

template<typename _Tp, size_t fixed_size = 4096/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

§ size

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

size of the real buffer


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