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. | |
~BufferArea () | |
Class destructor. | |
template<typename T > | |
void | allocate (T *&ptr, size_t count, ushort alignment=sizeof(T)) |
Bind a pointer to local area. | |
void | commit () |
Allocate memory and initialize all bound pointers. | |
void | release () |
Release all memory and unbind all pointers. | |
void | zeroFill () |
Fill all buffers with zeroes. | |
template<typename T > | |
void | zeroFill (T *&ptr) |
Fill one of buffers with zeroes. | |
Detailed Description
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:
- Note
- This class is considered private and should be used only in OpenCV itself. API can be changed.
Constructor & Destructor Documentation
◆ BufferArea()
cv::utils::BufferArea::BufferArea | ( | bool | safe = false | ) |
Class constructor.
- Parameters
-
safe Enable safe operation mode, each allocation will be performed independently.
◆ ~BufferArea()
cv::utils::BufferArea::~BufferArea | ( | ) |
Class destructor.
All allocated memory well be freed. Each bound pointer will be reset to NULL.
Member Function Documentation
◆ allocate()
|
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.
- Parameters
-
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.
- Note
- In safe mode allocation will be performed immediatly.
◆ commit()
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.
- Note
- Does nothing in safe mode as all allocations will be performed by BufferArea::allocate
◆ release()
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.
◆ zeroFill() [1/2]
void cv::utils::BufferArea::zeroFill | ( | ) |
Fill all buffers with zeroes.
BufferArea::commit must be called before using this method
◆ zeroFill() [2/2]
|
inline |
Fill one of buffers with zeroes.
- Parameters
-
ptr pointer to memory block previously added using BufferArea::allocate
BufferArea::commit must be called before using this method
The documentation for this class was generated from the following file:
- opencv2/core/utils/buffer_area.private.hpp