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
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.
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.
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
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.