Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: RZ_A2M_Mbed_samples
AutoBuffer< _Tp, fixed_size > Class Template Reference
[Utility and system functions and macros]
Automatically Allocated Buffer Class. More...
#include <utility.hpp>
Public Member Functions | |
AutoBuffer () | |
the default constructor | |
AutoBuffer (size_t _size) | |
constructor taking the real buffer size | |
AutoBuffer (const AutoBuffer< _Tp, fixed_size > &buf) | |
the copy constructor | |
AutoBuffer< _Tp, fixed_size > & | operator= (const AutoBuffer< _Tp, fixed_size > &buf) |
the assignment operator | |
~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 | |
void | deallocate () |
deallocates the buffer if it was dynamically allocated | |
void | resize (size_t _size) |
resizes the buffer and preserves the content | |
size_t | size () const |
returns the current buffer size | |
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 | |
Protected Attributes | |
_Tp * | ptr |
pointer to the real buffer, can point to buf if the buffer is small enough | |
size_t | sz |
size of the real buffer | |
_Tp | buf [(fixed_size > 0)?fixed_size:1] |
pre-allocated buffer. At least 1 element to confirm C++ standard reqirements |
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; // 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 ... }
Definition at line 114 of file utility.hpp.
Constructor & Destructor Documentation
AutoBuffer | ( | ) |
the default constructor
AutoBuffer | ( | size_t | _size ) |
constructor taking the real buffer size
AutoBuffer | ( | const AutoBuffer< _Tp, fixed_size > & | buf ) |
the copy constructor
~AutoBuffer | ( | ) |
destructor. calls deallocate()
Member Function Documentation
void allocate | ( | size_t | _size ) |
allocates the new buffer of size _size. if the _size is small enough, stack-allocated buffer is used
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<_Tp, fixed_size>& operator= | ( | const AutoBuffer< _Tp, fixed_size > & | buf ) |
the assignment operator
void resize | ( | size_t | _size ) |
resizes the buffer and preserves the content
size_t size | ( | ) | const |
returns the current buffer size
Field Documentation
_Tp buf[(fixed_size > 0)?fixed_size:1] [protected] |
pre-allocated buffer. At least 1 element to confirm C++ standard reqirements
Definition at line 151 of file utility.hpp.
_Tp* ptr [protected] |
pointer to the real buffer, can point to buf if the buffer is small enough
Definition at line 147 of file utility.hpp.
size_t sz [protected] |
size of the real buffer
Definition at line 149 of file utility.hpp.
Generated on Tue Jul 12 2022 18:20:23 by
