I know of storage classes in both C and C++ (static, extern, auto, register, C++ also adds mutable and some compiler-specific ones) but I can't figure out what a storage allocator is. I don't think it's referred to memory allocators implementable on STL, what is it in simple terms?
It's whatever is behind operator new
and operator delete
(not to be confused with the new
operator and the delete
operator). operator new
allocates memory from the free store, and operator delete
releases memory previously allocated by operator new
for possible reuse. When code does foo *ptr = new foo
(new
operator), the compiler generates code that calls operator new
to get the right number of bytes of storage, then calls the constructor for foo
. When code does delete ptr
(delete
operator) the compiler calls the destructor for foo
, then calls operator delete
to release the memory.
Note that this is how the term is used in the C++03 standard. In the C++11 standard it is also used to refer to standard allocators.
In the C++ standard, that term is used to refer to the allocator class used by STL-style containers - either std::allocator
, or a user-defined custom allocator that meets the requirements given by C++11 17.6.3.5.
However, it's not a formally defined term, and also appears once referring to the implementation of the free store - that is, the dynamic storage allocated by new
.
[NOTE: I'm referring to the current (2011) language specification. As noted in the comments, historical versions of the specification apparently only used the term (informally) to refer to the free store]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With