因为开发FreeSWITCH,接触到Apache的函数库libapr。
对于其字符串函数的工作方式很不理解,请教一下。
这个函数的格式如下:
char* apr_pstrndup ( apr_pool_t * p, const char * s, apr_size_t n )
Duplicate at most n characters of a string into memory allocated out of a pool; the new string will be NUL-terminated
Parameters:
p The pool to allocate out of
s The string to duplicate
n The maximum number of characters to duplicate
Returns:
The new string
Remarks:
The amount of memory allocated from the pool is the length of the returned string including the NUL terminator
看上去很好理解,就是从内存池中分配一个新的空间,把现有内容复制过去。
但是问题来了:我没有看到清理这片内存的函数。也就是说,这片被分配的内容,要一直等到内存池被销毁的时候,才会被清理吗?这样也太不科学了。
有哪位大神可以解答一下我的疑问?