.\" Man page generated from reStructuredText. . . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .TH "TSMALLOC" "3ts" "Jan 06, 2024" "9.2" "Apache Traffic Server" .SH NAME TSmalloc \- traffic Server memory allocation API .SH SYNOPSIS .INDENT 0.0 .INDENT 3.5 .sp .EX #include .EE .UNINDENT .UNINDENT .INDENT 0.0 .TP .B void *TSmalloc(size_t size) .UNINDENT .INDENT 0.0 .TP .B void *TSrealloc(void *ptr, size_t size) .UNINDENT .INDENT 0.0 .TP .B char *TSstrdup(const char *str) .UNINDENT .INDENT 0.0 .TP .B char *TSstrndup(const char *str, size_t size) .UNINDENT .INDENT 0.0 .TP .B size_t TSstrlcpy(char *dst, const char *src, size_t size) .UNINDENT .INDENT 0.0 .TP .B size_t TSstrlcat(char *dst, const char *src, size_t size) .UNINDENT .INDENT 0.0 .TP .B void TSfree(void *ptr) .UNINDENT .SH DESCRIPTION .sp Traffic Server provides a number of routines for allocating and freeing memory. These routines correspond to similar routines in the C library. For example, \fI\%TSrealloc()\fP behaves like the C library routine \fBrealloc\fP\&. 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 Servers supported platforms. For example, \fBrealloc\fP does not accept an argument of \fBNULL\fP 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. .sp \fI\%TSmalloc()\fP returns a pointer to size bytes of memory allocated from the heap. Traffic Server uses \fI\%TSmalloc()\fP internally for memory allocations. Always use \fI\%TSfree()\fP to release memory allocated by \fI\%TSmalloc()\fP; do not use \fBfree\fP\&. .sp \fI\%TSstrdup()\fP 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 \fI\%TSmalloc()\fP and should be freed by a call to \fI\%TSfree()\fP\&. \fI\%TSstrndup()\fP returns a pointer to a new string that is a duplicate of the string pointed to by \fIstr\fP but is at most \fIsize\fP bytes long. The new string will be NUL\-terminated. This API is very useful for transforming non NUL\-terminated string values returned by APIs such as \fI\%TSMimeHdrFieldValueStringGet()\fP into NUL\-terminated string values. The memory for the new string is allocated using \fI\%TSmalloc()\fP and should be freed by a call to \fI\%TSfree()\fP\&. .sp \fI\%TSstrlcpy()\fP copies up to \fIsize\fP \- 1 characters from the NUL\-terminated string \fIsrc\fP to \fIdst\fP, NUL\-terminating the result. .sp \fI\%TSstrlcat()\fP appends the NUL\-terminated string \fIsrc\fP to the end of \fIdst\fP\&. It will append at most \fIsize\fP \- \fBstrlen(dst)\fP \- 1 bytes, NUL\-terminating the result. .sp \fI\%TSfree()\fP releases the memory allocated by \fI\%TSmalloc()\fP or \fI\%TSrealloc()\fP\&. If ptr is \fBNULL\fP, \fI\%TSfree()\fP does no operation. .SH SEE ALSO .sp \fBTSAPI(3ts)\fP .SH COPYRIGHT 2024, dev@trafficserver.apache.org .\" Generated by docutils manpage writer. .