mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
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:
@@ -82,7 +82,7 @@ cv::utils::AllocatorStatisticsInterface& getAllocatorStatistics()
|
||||
return allocator_stats;
|
||||
}
|
||||
|
||||
#if defined HAVE_POSIX_MEMALIGN || defined HAVE_MEMALIGN
|
||||
#if defined HAVE_POSIX_MEMALIGN || defined HAVE_MEMALIGN || defined HAVE_WIN32_ALIGNED_MALLOC
|
||||
static bool readMemoryAlignmentParameter()
|
||||
{
|
||||
bool value = true;
|
||||
@@ -148,6 +148,14 @@ void* fastMalloc(size_t size)
|
||||
return OutOfMemoryError(size);
|
||||
return ptr;
|
||||
}
|
||||
#elif defined HAVE_WIN32_ALIGNED_MALLOC
|
||||
if (isAlignedAllocationEnabled())
|
||||
{
|
||||
void* ptr = _aligned_malloc(size, CV_MALLOC_ALIGN);
|
||||
if(!ptr)
|
||||
return OutOfMemoryError(size);
|
||||
return ptr;
|
||||
}
|
||||
#endif
|
||||
uchar* udata = (uchar*)malloc(size + sizeof(void*) + CV_MALLOC_ALIGN);
|
||||
if(!udata)
|
||||
@@ -170,6 +178,12 @@ void fastFree(void* ptr)
|
||||
free(ptr);
|
||||
return;
|
||||
}
|
||||
#elif defined HAVE_WIN32_ALIGNED_MALLOC
|
||||
if (isAlignedAllocationEnabled())
|
||||
{
|
||||
_aligned_free(ptr);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if(ptr)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user