Ask Your Question
0

How to redefine the Memory Allocator

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

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
0

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

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

Comments

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 -0600 )edit
-1

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

TripleS gravatar image

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

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:

Mat::setDefaultAllocator()

worked for me

S

edit flag offensive delete link more

Comments

2

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 -0600 )edit

Question Tools

Stats

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

Seen: 1,915 times

Last updated: Nov 15 '17