Ask Your Question
0

How to redefine the Memory Allocator

asked Apr 9 '13

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.

Preview: (hide)

2 answers

Sort by » oldest newest most voted
0

answered Apr 9 '13

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.

Preview: (hide)

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 (Apr 9 '13)edit
-1

answered Nov 15 '17

TripleS gravatar image

updated Nov 15 '17

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

Preview: (hide)

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 (Nov 15 '17)edit

Question Tools

Stats

Asked: Apr 9 '13

Seen: 1,967 times

Last updated: Nov 15 '17