opencv
2.2.0
|
#include <core.hpp>
Public Types | |
typedef _Tp | value_type |
Public Member Functions | |
void | allocate (size_t _size) |
allocates the new buffer of size _size. if the _size is small enough, stack-allocated buffer is used | |
AutoBuffer () | |
the default contructor | |
AutoBuffer (size_t _size) | |
constructor taking the real buffer size | |
void | deallocate () |
deallocates the buffer if it was dynamically allocated | |
operator _Tp * () | |
returns pointer to the real buffer, stack-allocated or head-allocated | |
operator const _Tp * () const | |
returns read-only pointer to the real buffer, stack-allocated or head-allocated | |
~AutoBuffer () | |
destructor. calls deallocate() | |
Protected Attributes | |
_Tp | buf [fixed_size] |
pre-allocated buffer | |
_Tp * | ptr |
pointer to the real buffer, can point to buf if the buffer is small enough | |
size_t | size |
size of the real buffer | |
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:
typedef _Tp cv::AutoBuffer< _Tp, fixed_size >::value_type |
|
inline |
the default contructor
|
inline |
constructor taking the real buffer size
|
inline |
destructor. calls deallocate()
|
inline |
allocates the new buffer of size _size. if the _size is small enough, stack-allocated buffer is used
|
inline |
deallocates the buffer if it was dynamically allocated
|
inline |
returns pointer to the real buffer, stack-allocated or head-allocated
|
inline |
returns read-only pointer to the real buffer, stack-allocated or head-allocated
|
protected |
pre-allocated buffer
|
protected |
pointer to the real buffer, can point to buf if the buffer is small enough
|
protected |
size of the real buffer