Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7964649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:56:30+00:00 2026-06-04T05:56:30+00:00

Is it possible to set a custom allocator for OpenCV 2.3.1? I have a

  • 0

Is it possible to set a custom allocator for OpenCV 2.3.1? I have a memory pool created and I want OpenCV to use that pool for what it needs.

Is that possible?
If it is, how can it be done?

Updated:

I made some developments since last answer, but I still have some problems.
This is the code I have now:

CvAllocFunc allocCV() 
{ 
     return (CvAllocFunc) MEMPOOL->POOLalloc(sz); 
}

CvFreeFunc deallocCV()
{
    return (CvFreeFunc) MEMPOOL->POOLfree(ptr);
}

...

cvSetMemoryManager(allocCV(),deallocCV(),data);

Now, my question is, how can I have access to the size and the pointer to the data I want to allocate and later to deallocate?

Just found out:
The version of OpenCV I’m using (2.3.1) throws an error when using cvSetMemoryManager. The reason is in its source code:

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

I was very disappointed with this. I guess I can’t use a custom memory pool with OpenCV anymore!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:56:31+00:00Added an answer on June 4, 2026 at 5:56 am

    Right from the docs

    http://opencv.willowgarage.com/documentation/c/core_utility_and_system_functions_and_macros.html#setmemorymanager

    Use the

    void cvSetMemoryManager(CvAllocFunc allocFunc=NULL, CvFreeFunc freeFunc=NULL, void* userdata=NULL)
    

    function.

    Your code

    cvSetMemoryManager(allocCV(),deallocCV(),data);
    

    is WRONG.

    See what happens: you call allocCV and deallocCV functions (they return some pointer which is quietly converted to cvAllocFunc) !

    And this is only the beginning. See the docs for alloc/dealloc semantics. You should write allocCV/deallocCV with correct signatures.

    void* CV_CDECL allocCV(size_t size, void* userdata)
    {
         return ((YourMemPoolTypeWhichIDoNotKnow*)userdata)->POOLalloc(size);
    }
    
    int CV_CDECL deallocCV(void* pptr, void* userdata)
    {
        return ((YourMemPoolTypeWhichIDoNotKnow*)userdata)->POOLfree(pptr);
    }
    

    and then pass your MEMPOOL in the ‘userdata’ parameter:

    cvSetMemoryManager(&allocCV, &deallocCV, (void*)MEMPOOL);
    

    This is a standard way for a library to provide user callbacks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to have nested set capabilities in this somewhat custom setup? Consider
I have created a set of custom HtmlHelper extensions. I would like to know
I've heard (well read, at http://www.ddj.com/windows/184416861 ), that it's possible to set custom properties
I have a set of the custom fonts (not the system fonts) that I
Is it possible in ZendFramework to set custom template when I call some action
Is it possible to set a default behaviour for custom (non-native) methods/functions in Java?
I'm trying to make a set of custom tags that encapsulate form elements (markup
Is it possible to set custom flags on IMAP mail messages using java mail
In VS, it is possible to set a custom build rule at the individual
I have a set of custom PHP forms within a set of Drupal pages

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.