自动分配缓冲区类
Automatically Allocated Buffer Class.
这个类用于函数和方法中的临时缓冲区。如果临时缓冲区通常很小(几K的内存),但其大小取决于参数,则在堆栈上创建一个小的固定大小数组,并在足够大时使用它是有意义的。如果所需缓冲区的大小大于固定大小,则动态分配另一个足够大的缓冲区,并在处理后释放它。因此,在典型情况下,当缓冲区大小很小时,与malloc()/ free()相关的开销是没有的。同时,对处理的数据大小没有限制。
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
...
}
当使用的临时内存小于预分配的内存大小时,无需动态malloc/free,可以直接从内存池中取用,提高了性能
变量名buf