MLDeallocator (C 函数)
MLDeallocator 已经被 WSDeallocator 所取代.
是一个 MathLink 类型,描述一个指向取 void * 作为自变量的函数的函数指针,并返回实现内存释放器的 void 类型.
范例
基本范例 (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;
}