What is the difference between memory allocation through new and allocator

What is the difference between memory allocation via new/ mallocand allocator?

Why would we ever need a separate memory allocator for a vector if we have the newand options malloc?

+5
source share
4 answers

When you use new or malloc, memory management is tightly coupled with the corresponding functions at runtime of your compiler. In contrast, when a allocator is used, memory management is delegated to a allocator, which can be replaced. This allows you to change the memory management functions used.

. , . STL-STL?.

+2

Eh, , new malloc , allocator . malloc , calloc . new , ( int, bool , , , ). delete , free - .

allocator, . allocator , . STL allocator, .

, , allocator , allocator , new/delete. , . , , . new, . , allocator , . , allocator s .

, std::allocator, , .


allocator s.

+1

allocator allocate(), :

pointer allocate (size_type n, allocator<void>::const_pointer hint=0);

allocate() , , , . , , , .

0

A allocator is a memory manager. For example, STL containers provide default dispensers, but they can be configured as an explanation in this article (tutorial for STL dispensers): http://www.codeguru.com/cpp/cpp/cpp_mfc/stl/article.php/c4079/Allocators -STL.htm .

0
source

All Articles