add windows native aligned malloc + unit test case

* implements https://github.com/opencv/opencv/issues/19147
* CAUTION: this PR will only functions safely in the
  4+ branches that already include PR 19029
* CAUTION: this PR requires thread-safe startup of the alloc.cpp
  translation unit as implemented in PR 19029
This commit is contained in:
Dale Phurrough
2020-12-23 14:59:28 +01:00
parent 619cc01ca1
commit 109255a730
4 changed files with 42 additions and 2 deletions
+14
View File
@@ -2,6 +2,7 @@
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "test_precomp.hpp"
#include <cmath>
namespace opencv_test { namespace {
@@ -783,5 +784,18 @@ TEST(Core_Check, testSize_1)
}
}
TEST(Core_Allocation, alignedAllocation)
{
// iterate from size=1 to approximate byte size of 8K 32bpp image buffer
for (int i = 0; i < 200; i++) {
const size_t size = static_cast<size_t>(std::pow(1.091, (double)i));
void * const buf = cv::fastMalloc(size);
ASSERT_NE((uintptr_t)0, (uintptr_t)buf)
<< "failed to allocate memory";
ASSERT_EQ((uintptr_t)0, (uintptr_t)buf % CV_MALLOC_ALIGN)
<< "memory not aligned to " << CV_MALLOC_ALIGN;
cv::fastFree(buf);
}
}
}} // namespace