CV_Assert(alignment % sizeof(T) == 0);
CV_Assert((alignment & (alignment - 1)) == 0);
allocate_((void**)(&ptr), static_cast<ushort>(sizeof(T)), count, alignment);
+#ifndef OPENCV_ENABLE_MEMORY_SANITIZER
+ if (safe)
+#endif
+ CV_Assert(ptr != NULL);
}
/** @brief Fill one of buffers with zeroes
private:
class Block;
std::vector<Block> blocks;
+#ifndef OPENCV_ENABLE_MEMORY_SANITIZER
void * oneBuf;
size_t totalSize;
const bool safe;
+#endif
};
//! @}
#include "opencv2/core/utils/buffer_area.private.hpp"
#include "opencv2/core/utils/configuration.private.hpp"
-#ifdef OPENCV_ENABLE_MEMORY_SANITIZER
-#define BUFFER_AREA_DEFAULT_MODE true
-#else
-#define BUFFER_AREA_DEFAULT_MODE false
-#endif
-
+#ifndef OPENCV_ENABLE_MEMORY_SANITIZER
static bool CV_BUFFER_AREA_OVERRIDE_SAFE_MODE =
- cv::utils::getConfigurationParameterBool("OPENCV_BUFFER_AREA_ALWAYS_SAFE", BUFFER_AREA_DEFAULT_MODE);
+ cv::utils::getConfigurationParameterBool("OPENCV_BUFFER_AREA_ALWAYS_SAFE", false);
+#endif
namespace cv { namespace utils {
*ptr = raw_mem;
}
}
+#ifndef OPENCV_ENABLE_MEMORY_SANITIZER
void * fast_allocate(void * buf) const
{
CV_Assert(ptr && *ptr == NULL);
*ptr = buf;
return static_cast<void*>(static_cast<uchar*>(*ptr) + type_size * count);
}
+#endif
bool operator==(void **other) const
{
CV_Assert(ptr && other);
//==================================================================================================
+#ifndef OPENCV_ENABLE_MEMORY_SANITIZER
BufferArea::BufferArea(bool safe_) :
oneBuf(0),
totalSize(0),
safe(safe_ || CV_BUFFER_AREA_OVERRIDE_SAFE_MODE)
{
+ // nothing
}
+#else
+BufferArea::BufferArea(bool safe_)
+{
+ CV_UNUSED(safe_);
+}
+#endif
BufferArea::~BufferArea()
{
void BufferArea::allocate_(void **ptr, ushort type_size, size_t count, ushort alignment)
{
blocks.push_back(Block(ptr, type_size, count, alignment));
- if (safe)
- blocks.back().real_allocate();
- else
+#ifndef OPENCV_ENABLE_MEMORY_SANITIZER
+ if (!safe)
+ {
totalSize += blocks.back().getByteCount();
+ }
+ else
+#endif
+ {
+ blocks.back().real_allocate();
+ }
}
void BufferArea::zeroFill_(void **ptr)
void BufferArea::commit()
{
+#ifndef OPENCV_ENABLE_MEMORY_SANITIZER
if (!safe)
{
CV_Assert(totalSize > 0);
ptr = i->fast_allocate(ptr);
}
}
+#endif
}
void BufferArea::release()
i->cleanup();
}
blocks.clear();
+#ifndef OPENCV_ENABLE_MEMORY_SANITIZER
if (oneBuf)
{
fastFree(oneBuf);
oneBuf = 0;
}
+#endif
}
//==================================================================================================