What is a <T> spreader

I am trying to implement a vector, and I read that the best implementation uses the allocator class (memory header file). I have no idea what it is, and cplusplus.com did not help me at all.

+3
source share
2 answers

This is an abstraction of memory management.

In C programming, you essentially use the functions malloc()and free()to allocate memory fragments, without the need to know how the pieces are distributed. In C ++, the functions operator new()and operator delete().

std::allocator - , , . std::allocator operator new() operator delete() , , std::allocator<T> , T , , T.

std::allocator<T>:

  • allocate(size_type n)

    operator new() n * sizeof (T) . : n T ; new T(), T no-arg, allocate(size_type n) n T. construct() .

  • deallocate(pointer p, size_type n)

    operator delete(), , , allocate(). , deallocate() . destroy() n T, .

  • construct(pointer p, const T& val)

    T T, p.

  • destroy(pointer p)

    T T, p.

+6

, .
, , , std::allocator .

0

All Articles