WSAllocator
This feature is not supported on the Wolfram Cloud.


is a WSTP type that describes a function pointer to a function taking an unsigned long argument and returning a void * that implements a memory allocator.

DetailsDetails

  • The memory allocator function must be thread-safe.
  • On 64-bit Windows platforms the allocator takes an unsigned __mlint64 as an argument.
  • WSAllocator() 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;
    WSParameters p;
    int error;

    WSSetAllocParameter((char *)p, AppAllocator, AppDeallocator);

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

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

    /* ... */

    WSClose(link);
    WSDeinitialize(env);

    return 0;
}