Why a 40-bit memory leak, it really should have been 4 bytes.
It should do both additional information about a dynamically distributed object and effective management of dynamic (heap) memory 1, 2 .
As for the first, information must be available so that the allocated heap memory is freed after the end of the object's life.
As for the latter, there is something called bandwidth, and it does not have to be equal to the allocated size. It can be equal or large, with additional space that allows you to take into account growth without the need for redistribution with each insert.
Please note that this capacity does not allow restrictions on the type size in your int case.
Example:
vector are sequence containers representing arrays that can vary in size. Internally, vectors use a dynamically allocated array to store their elements. Calling the following three member functions of vector :
size()
max_size()
capacity()
will return different values ββand give you some idea of ββthe strategy used to allocate heap memory.
1. If the originally allocated object is to grow, it may be required that it be completely redistributed rather than expanded into an adjacent / continuous memory section. Involving a large number of operations.
2. To align the memory, an additional addition can be added (multiplicity of 4 bytes, so that it can be read with less access to memory)
Ziezi
source share