MLSetAllocParameter()

void MLSetAllocParameter(char* p, MLAllocator a, MLDeallocator d)
sets the memory allocator and deallocator specified by a and d in the MLParameters object p for later use with MLInitialize().

DetailsDetails

  • Use MLSetAllocParameter() to install special memory allocators in the MathLink library. The library will use the allocators specified by a and d for all dynamic memory allocations.
  • a and d must have the same call signature as the C memory allocator functions malloc() and free().
  • a and d must be thread-safe.
  • MLSetAllocParameter() is declared in the MathLink header file mathlink.h.

ExamplesExamplesopen allclose all

Basic Examples (1)Basic Examples (1)

#include "mathlink.h"

void * Custom_Allocator(size_t size)
{
    /* ... */
}

void Custom_Deallocator(void *ptr)
{
    /* ... */
}


int main()
{
    MLEnvironment env;
    MLParameters p;
    unsigned long revision;

    revision = MLNewParameters((char *)&p, MLREVISION, MLAPIREVISION);
    if(! revision)
        { /* unable to initialize the MLParameters object */ }

    MLSetAllocParameter(&p, Custom_Allocator, Custom_Deallocator);

    /* Install the Custom* memory allocator in MathLink. */
    env = MLInitialize(&p);
    if(env == (MLENV)0)
        { /* unable to initialize MathLink environment */ }

    /* ... */

    MLDeinitialize(env);
    return 0;
}
New to Mathematica? Find your learning path »
Have a question? Ask support »