Shenzhen Tianteng Industry Co.,Ltd
You Are Here:Home > NEWS > Content
The Distributor Is An Important Part Of The C++ Standard Library In C++ Programming
Jun 25, 2018

In C++ programming, the allocator is an important part of the C++ standard library. The C++ library defines a variety of data structures (such as linked lists, collections, etc.) that are collectively referred to as "containers." One of the common features of these containers is that their sizes can be changed at runtime; in order to achieve this, Dynamic memory allocation is particularly necessary, in this dispenser is used to deal with the container's memory allocation and release requests. In other words, the allocator is used to encapsulate the low-level details of memory management in STL containers. By default, the C++ standard library uses its own universal allocator, but programmers can also customize the distributor to replace it, depending on the needs.

The distributor was first invented by Alexander Stepnenov as part of the Standard Template Library (STL) for the C++. Its original intention was to create a method that "makes the library more flexible and independent of the underlying data model. And allows programmers to take advantage of custom pointers and reference types in the library; but when incorporating the standard templating library into the C++ standard, the C++ standards committee realized that the complete abstraction of the data model would result in unacceptable performance loss, In order to make a compromise, the restrictions on dispensers in the standard have become more stringent, and in view of this, the degree of customization of the dispensers described by the existing standards has been greatly limited compared with Stefanov's original idea.

Although the customization of the distributor is limited, in many cases, a custom allocator is still needed, which is generally to encapsulate access to different types of memory space (such as shared memory and recycled memory), or Improve performance when using memory pools for memory allocation. In addition to this, from the perspective of memory usage and runtime, it is also beneficial to introduce a specially-designed distributor for programs that frequently perform a small amount of memory allocation.