TSMalloc(3ts)

NAME
TSMalloc, TSrealloc, TSstrdup, TSstrndup, TSstrlcpy, TSstrlcat, TSfree - TrafficServer memory allocation APIs

LIBRARY
Apache Traffic Server plugin API

SYNOPSIS
#include <ts/ts.h>
void *
TSmalloc(size_t size, const char * path);
void *
TSrealloc(void * ptr, size_t size, const char * path);
char *
TSstrdup(const char * str, int64_t length, const char * path);
size_t
TSstrlcpy(char * dst, const char * src, size_t size);
size_t
TSstrlcat(char * dst, const char * src, size_t size);
void
TSfree(void * ptr);

DESCRIPTION
Traffic Server provides a number of routines for allocating and freeing memory. These routines correspond to similar routines in the C library. For example, TSrealloc() behaves like the C library routine realloc(). There are two reasons to use the routines provided by Traffic Server. The first is portability. The Traffic Server API routines behave the same on all of Traffic Server’s supported platforms. For example, realloc() does not accept an argument of NULL on some platforms. The second reason is that the Traffic Server routines actually track the memory allocations by file and line number. This tracking is very efficient, is always turned on, and is useful for tracking down memory leaks. TSmalloc() returns a pointer to size bytes of memory allocated from the heap. Traffic Server uses TSmalloc() internally for memory allocations. Always use TSfree() to release memory allocated by TSmalloc(;, do, not) use free(). TSstrdup() returns a pointer to a new string that is a duplicate of the string pointed to by str. The memory for the new string is allocated using TSMalloc() and should be freed by a call to TSfree(). TSstrndup() returns a pointer to a new string that is a duplicate of the string pointed to by str and length bytes long. The new string will be NULL-terminated. This API is very useful for transforming non NULL-terminated string values returned by APIs such as TSMimeHdrFieldStringValueGet() into NULL-terminated string values. The memory for the new string is allocated using TSmalloc(and) should be freed by a call to TSfree(). TSstrlcpy() copies up to size - 1 characters from the NULL-terminated string src to dst, NULL-terminating the result. TSstrlcat() appends the NULL-terminated string src to the end of dst. It will append at most size - strlen(dst) - 1 bytes, NULL-terminating the result. TSfree() releases the memory allocated by Tsmalloc() or TSrealloc(). If ptr is NULL, TSfree() does no operation.

SEE ALSO
TSAPI(3ts)