MLSetAllocParameter()
This feature is not supported on the Wolfram Cloud.

has been replaced by WSSetAllocParameter.

void MLSetAllocParameter(MLEnvironmentParameter p,MLAllocator a,MLDeallocator d)
sets the memory allocator and deallocator specified by a and d in the MLEnvironmentParameter 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;
    MLEnvironmentParameter p;
    unsigned long revision;

    p = MLNewParameters(MLREVISION, MLAPIREVISION);
    if(p == (MLEnvironmentParameter)0))
    { /* unable to initialize the MLEnvironmentParameters object */ }

    MLSetAllocParameter(ep, Custom_Allocator, Custom_Deallocator);

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

    MLReleaseParameters(p);

    /* ... */

    MLDeinitialize(env);
    return 0;
}