OpenCV
3.4.18
Open Source Computer Vision
|
Manages memory block shared by muliple buffers. More...
#include <opencv2/core/utils/buffer_area.private.hpp>
Public Member Functions | |
BufferArea (bool safe=false) | |
Class constructor. More... | |
~BufferArea () | |
Class destructor. More... | |
template<typename T > | |
void | allocate (T *&ptr, size_t count, ushort alignment=sizeof(T)) |
Bind a pointer to local area. More... | |
void | commit () |
Allocate memory and initialize all bound pointers. More... | |
void | release () |
Release all memory and unbind all pointers. More... | |
template<typename T > | |
void | zeroFill (T *&ptr) |
Fill one of buffers with zeroes. More... | |
void | zeroFill () |
Fill all buffers with zeroes. More... | |
Manages memory block shared by muliple buffers.
This class allows to allocate one large memory block and split it into several smaller non-overlapping buffers. In safe mode each buffer allocation will be performed independently, this mode allows dynamic memory access instrumentation using valgrind or memory sanitizer.
Safe mode can be explicitly switched ON in constructor. It will also be enabled when compiling with memory sanitizer support or in runtime with the environment variable OPENCV_BUFFER_AREA_ALWAYS_SAFE
.
Example of usage:
cv::utils::BufferArea::BufferArea | ( | bool | safe = false | ) |
Class constructor.
safe | Enable safe operation mode, each allocation will be performed independently. |
cv::utils::BufferArea::~BufferArea | ( | ) |
Class destructor.
All allocated memory well be freed. Each bound pointer will be reset to NULL.
|
inline |
Bind a pointer to local area.
BufferArea will store reference to the pointer and allocation parameters effectively owning the pointer and allocated memory. This operation has the same parameters and does the same job as the operator new
, except allocation can be performed later during the BufferArea::commit call.
ptr | Reference to a pointer of type T. Must be NULL |
count | Count of objects to be allocated, it has the same meaning as in the operator new . |
alignment | Alignment of allocated memory. same meaning as in the operator new (C++17). Must be divisible by sizeof(T). Must be power of two. |
void cv::utils::BufferArea::commit | ( | ) |
Allocate memory and initialize all bound pointers.
Each pointer bound to the area with the BufferArea::allocate will be initialized and will be set to point to a memory block with requested size and alignment.
void cv::utils::BufferArea::release | ( | ) |
Release all memory and unbind all pointers.
All memory will be freed and all pointers will be reset to NULL and untied from the area allowing to call allocate
and commit
again.
|
inline |
Fill one of buffers with zeroes.
ptr | pointer to memory block previously added using BufferArea::allocate |
BufferArea::commit must be called before using this method
void cv::utils::BufferArea::zeroFill | ( | ) |
Fill all buffers with zeroes.
BufferArea::commit must be called before using this method