C++: Memory allocators

前端 未结 5 1112
情话喂你
情话喂你 2020-12-25 15:51

I\'ve heard about people using custom memory allocators for their project, particulary in C++.

  • What is a custom memory allocator, compared to malloc?

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-25 16:14

    malloc() is a library function in libc (or glibc) that makes a system call sbrk() when it needs to actually allocate more memory to the process. Together, malloc() and free() manage a list of memory blocks that are used when malloc(), calloc() etc. are called.

    You can use a custom allocator when malloc()'s behavior isn't desired or you want to do additional work on top of malloc/free.

提交回复
热议问题