c++ - Does the standard guarantee that the total memory occupied by a std::vector scales as C+N*sizeof(T)? -


C ++ standard guarantees that std :: vector content is contiguously stored but does it say that total capture Memory is:

  S = C + N * sizeof (T)   

Where:

  • Total on S heap Size and Stack
  • The total size on the heap is: C = size (std :: vector)
  • The capacity of the vector is
  • stored in T type

    In other words, do I guarantee that the per element is not per overhead? ? And if I do not have such a guarantee then is there any reason?

    Edit: To be clear, if I take the example of std :: list , then this is usually 2 extra pointers per element, then my question is: Code> std :: vector must be standard-compliant?

    For such a guarantee, the standard needs to pass the need for the interface of the allocation. Not so, it is not so.

    However, in practice, as the quality of the issue of implementation, you expect that allocation of memory allocation is consistently upper part, but no upper portion is proportional to the proportional allocation . A copy-example of this would be a memory allocation that uses a power-of-two-size block regardless of the size requested, it would be very useless for large allocation, but allocation defined by the user or even so far That system used by :: operators new [] has not been denied as a Olocator. This would make an overhead proportional to the N on average, assuming that the vector capacity does not fit well.

    Except the allocation, I do not believe that there is nothing in it to say in the standard that vector can not allocate an extra bit per element (for example) and to store some flags It uses it-who knows-what purpose, as others have commented, the need for compatibility means that those extra bit vectors can not lie between the elements. At one end of the allocation, they have to have a different allocation or all together.

    At least one good reason is that implementing the standard is not used to store it from "wasted" space. The data used for operation is not required according to standard - By doing this many debugging techniques will be excluded!

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -