Options
All
  • Public
  • Public/Protected
  • All
Menu

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(1000); // 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
   ...
}

Source: opencv2/core/utility.hpp.

Hierarchy

  • AutoBuffer

Index

Constructors

constructor

Methods

allocate

  • allocate(_size: size_t): void

data

  • data(): any
  • data(): any

deallocate

  • deallocate(): void

resize

size

Generated using TypeDoc