WSSetAllocParameter (C Function)
void WSSetAllocParameter(WSEnvironmentParameter p,WSAllocator a,WSDeallocator d)
sets the memory allocator and deallocator specified by a and d in the WSEnvironmentParameter object p for later use with WSInitialize().
Details
- Use WSSetAllocParameter() to install special memory allocators in the WSTP 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.
- WSSetAllocParameter() is declared in the WSTP header file wstp.h.
Examples
Basic Examples (1)
#include "wstp.h"
void * Custom_Allocator(size_t size)
{
/* ... */
}
void Custom_Deallocator(void *ptr)
{
/* ... */
}
int main()
{
WSEnvironment env;
WSEnvironmentParameter p;
unsigned long revision;
p = WSNewParameters(WSREVISION, WSAPIREVISION);
if(p == (WSEnvironmentParameter)0))
{ /* unable to initialize the WSEnvironmentParameters object */ }
WSSetAllocParameter(ep, Custom_Allocator, Custom_Deallocator);
/* Install the Custom* memory allocator in WSTP. */
env = WSInitialize(ep);
if(env == (WSENV)0)
{ /* unable to initialize WSTP environment */ }
WSReleaseParameters(p);
/* ... */
WSDeinitialize(env);
return 0;
}