WSDeallocator
This feature is not supported on the Wolfram Cloud.


is a WSTP 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.

DetailsDetails

  • The memory deallocator function must be thread-safe.
  • WSDeallocator() is declared in the WSTP header file wstp.h.

ExamplesExamplesopen allclose all

Basic Examples  (1)Basic Examples  (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)
{
    MLENV env;
    MLINK link;
    WSEnvironmentParameter p;
    int error;

    p = WSNewParameters(WSREVISION, WSAPIREVISION);
    if(p == (WSEnvironmentParameter)0)
    { /* Unable to initialize a parameters object */ }

    WSSetAllocParameter(p, AppAllocator, AppDeallocator);

    env = WSInitialize(p);
    if(env == (MLENV)0)
    { /* unable to initialize the WSTP environment */ }

    WSReleaseParameters(p);

    link = WSOpenArgcArgv(env, argc, argv, &error);
    if(link == (MLINK)0)
    { /* unable to create the link */ }

    /* ... */

    WSClose(link);
    WSDeinitialize(env);

    return 0;
}