| OpenCV 4.3.0 Open Source Computer Vision

Public Member Functions | List of all members
cv::utils::BufferArea Class Reference
Core functionality » Utility and system functions and macros

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...

## 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:

int * buf1 = 0;
double * buf2 = 0;
cv::util::BufferArea area;
area.allocate(buf1, 200); // buf1 = new int[200];
area.allocate(buf2, 1000, 64); // buf2 = new double[1000]; - aligned by 64
area.commit();

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()

template<typename T >

void cv::utils::BufferArea::allocate | ( | T *& | ptr,
|  | size_t | count,
|  | ushort | alignment = `sizeof(T)`
| ) |  |
| 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]

template<typename T >

void cv::utils::BufferArea::zeroFill | ( | T *& | ptr | ) |
| 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

## ◆ zeroFill() [2/2]

void cv::utils::BufferArea::zeroFill | ( |  | ) |

Fill all buffers with zeroes.

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