TSmalloc¶
Traffic Server memory allocation API.
概要¶
#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)¶
-
char *
TSstrndup
(const char * str, size_t size)¶
-
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)¶
解説¶
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 Servers 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()
は str で指し示された文字列を複製した新しい文字列を指すポインターを返します。新しい文字列のメモリーは TSmalloc()
を使用して割り当てられ、TSfree()
の呼び出しに酔って解放されるべきです。TSstrndup()
は size バイトの長さの str で指し示された文字列を複製した新しい文字列を指すポインターを返します。新しい文字列は NUL 終端されます。この API は TSMimeHdrFieldValueStringGet()
などによって返された非 NUL 終端文字列値を NUL 終端文字列値に変換するのにとても便利です。新しい文字列のメモリーは TSmalloc()
を使用して割り当てられ、TSfree()
の呼び出しに酔って解放されるべきです。
TSstrlcpy()
は NUL 終端文字列 src から dst に size - 1 文字までコピーし、結果を NUL 終端します。`
TSstrlcat()
は NUL 終端文字列 src を dst の終わりに追加します。これは最大で size - strlen(dst) - 1 を追加し、結果を NUL 終端します。
TSfree()
は TSmalloc()
または TSrealloc()
によって割り当てられたメモリーを解放します。ptr が NULL
の場合、TSfree()
は何も行いません。
参考¶
TSAPI(3ts)