MLDeallocator (C Function)
MLDeallocator has been replaced by WSDeallocator.
is a MathLink type that describes a function pointer to a function taking a void * as an argument and having a return type of void that implements a memory deallocator.
Details
- The memory deallocator function must be thread-safe.
- MLDeallocator() is declared in the MathLink header file mathlink.h.
Examples
Basic Examples (1)
#include <stdlib.h>
#include "mathlink.h"
/* AppAllocator implements a custom memory allocator */
void * AppAllocator(unsigned long size)
{
return malloc(size);
}
/* AppDeallocator implements a custom memory deallocator */
void AppDeallocator(void *m)
{
free(m);
}
int main(int argc, char **argv)
{
MLENV env;
MLINK link;
MLEnvironmentParameter p;
int error;
p = MLNewParameters(MLREVISION, MLAPIREVISION);
if(p == (MLEnvironmentParameter)0)
{ /* Unable to initialize a parameters object */ }
MLSetAllocParameter(p, AppAllocator, AppDeallocator);
env = MLInitialize(p);
if(env == (MLENV)0)
{ /* unable to initialize the MathLink environment */ }
MLReleaseParameters(p);
link = MLOpenArgcArgv(env, argc, argv, &error);
if(link == (MLINK)0)
{ /* unable to create the link */ }
/* ... */
MLClose(link);
MLDeinitialize(env);
return 0;
}