linux - 为什么有的库中, 内存申请, 释放等函数要做成可修改的, 比如curl. malloc, realloc这种不是通用的吗?
阿神
阿神 2017-04-17 12:07:40
0
5
316

为什么有的库中, 内存申请, 释放等函数要做成可修改的, 比如curl. malloc, realloc这种不是通用的吗?

阿神
阿神

闭关修行中......

reply all(5)
伊谢尔伦

is not universal
Either expose the function of memory application and release, and apply for memory from the module.
The second method is the approach on Windows. The memory is managed by the user, but the memory size can be queried through functions. Many times, the Windows API is painfully called twice

黄舟
  1. Not all platforms may provide malloc implementation
  2. Customized malloc can save memory and improve performance
阿神

Many libraries have memory pool implementations. Ordinary malloc has to be encapsulated. The implementation of malloc and the like in the standard library is not necessarily the best, so there are implementations like jmalloc, which are more efficient. The standard malloc writing method is universal except for embedded systems. Basically C's standard library needs to implement these.

巴扎黑

For example, when you want to detect memory leaks, you need to add records to malloc.

阿神

Frequently calling malloc will cause memory fragmentation and the risk of memory leaks.

The solution is内存池: apply for large memory in advance and manage this memory yourself, which facilitates debugging and calculation of how much memory is used.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!