OpenersNotesSection(Spacer1)Details

The memory deallocator function must be thread-safe.

WSDeallocator() is declared in the WSTP header file (RefLink[wstp.h, paclet:ref/file/wstp.h]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (1)

OpenersExampleSection0(Spacer1)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)
{
	WSENV env;
	WSLINK 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 == (WSENV)0)
	{ /* unable to initialize the WSTP environment */ }

	WSReleaseParameters(p);

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

	/* ... */

	WSClose(link);
	WSDeinitialize(env);

	return 0;
}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(NonWLLink[WSAllocator(), paclet:ref/c/WSAllocator])  ▪  (NonWLLink[WSSetAllocParameter(), paclet:ref/c/WSSetAllocParameter])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[WSTP C API Developer Guide (Mac OS X), paclet:tutorial/WSTPDeveloperGuide-MacintoshOverview])}, {▪(RefLinkPlain[WSTP C API Developer Guide (Unix and Linux), paclet:tutorial/WSTPDeveloperGuide-UnixOverview])}, {▪(RefLinkPlain[WSTP C API Developer Guide (Windows), paclet:tutorial/WSTPDeveloperGuide-WindowsOverview])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Alphabetical Listing of WSTP C Functions, paclet:guide/AlphabeticalListingOfWSTPCFunctions])}})}})