Ask Your Question

How to redefine the Memory Allocator

asked 2013-04-09 02:08:45 -0500

artanis gravatar image

Hi all,

Sorry to disturb you.

Currently I want to redefine the memory allocator in OpenCV. However I found that the cvSetMemoryManager() function is useless. The source code of it is:

void cvSetMemoryManager(CvAllocFunc, CvFreeFunc, void *)
CV_Error( -1, "Custom memory allocator is not supported" );

Is there another way to redefine the memory allocator in OpenCV ?

Thank you.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2013-04-09 02:30:04 -0500

I guess the function says it all. Custom memory allocator is not supported by OpenCV. If you want to use a custom memory allocator, you will have to write overload functions and add own functionality to openCV, then build the whole library yourself. If you do so however, please create a pull request to add this functionality to the library.

edit flag offensive delete link more


I totally agree with you, opencv doesn't support custom memory allocator until now. However I find that there exists a memory pool in opencv, though it has never been used. I will try to make a pull request to implement cvSetMemoryManager, but it will need lots of testing.

artanis gravatar imageartanis ( 2013-04-09 03:48:54 -0500 )edit

answered 2017-11-15 02:23:18 -0500

TripleS gravatar image

updated 2017-11-15 02:24:20 -0500

Yes, you can redefine cv::Mat allocator !!!

Simple inherent from MatAllocator

Implement the virtual functions needed

Create a singleton instance for your allocator

Pass it to:


worked for me


edit flag offensive delete link more



just saying, please do not answer questions from 2013, e.g. the api in above question is no more used.

berak gravatar imageberak ( 2017-11-15 02:30:31 -0500 )edit

Question Tools


Asked: 2013-04-09 02:08:45 -0500

Seen: 1,490 times

Last updated: Nov 15 '17