WSAllocator (C 函数)
是一个 WSTP 类型,描述一个指向取 unsigned long 自变量的函数的函数指针,并返回实现内存分配器的 void *.
范例
基本范例 (1)
#include <stdlib.h>
#include "wstp.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)
{
WSENV env;
WSLINK link;
WSParameters p;
int error;
WSSetAllocParameter((char *)p, AppAllocator, AppDeallocator);
env = WSInitialize((char *)p);
if(env == (WSENV)0)
{ /* unable to initialize the WSTP environment */ }
link = WSOpenArgcArgv(env, argc, argv, &error);
if(link == (WSLINK)0)
{ /* unable to create the link */ }
/* ... */
WSClose(link);
WSDeinitialize(env);
return 0;
}