Actions
Bug #758
openOFVector needs to separate allocation and element construction
Start date:
2017-06-09
Due date:
% Done:
0%
Estimated time:
Module:
Operating System:
Compiler:
Description
The current OFVector implementation does not separate element construction from memory allocation, i.e.
capacity() == 10means at least 10 elements have been constructed even if
size() == 0. This is not only agains the C++ standard but also has serious ramifications:
1. The element type used within an OFVector needs to be default constructible, which is an unnecessary constraint that leads to inefficient code.
2. Recursive structures based on OFVector cause a stack overflow!! See this example:
struct Recursive : OFVector<Recursive>
{
// data members
};
Recursive r; // stack overflow, since the default constructor constructs elements, which themselves recursively construct more elements.
Updated by Jan Schlamelcher about 8 years ago
A partial workaround has been commited as #48e6422858b2a62 . This fixes issue 2. from above by removing the predictive allocation of some elements in OFVectors default constructor, which was probably a bad idea anyway, see for example: https://stackoverflow.com/questions/12271017/initial-capacity-of-vector-in-c . The commit also adds checks to the configuration test for std::vector and the unit test OFVector to ensure the problem will not be introduced again.
Updated by Jan Schlamelcher over 7 years ago
- Target version changed from 3.6.3 to 3.6.6
Updated by Marco Eichelberg about 5 years ago
- Priority changed from High to Normal
- Target version changed from 3.6.6 to 3.6.7
Updated by Michael Onken over 3 years ago
- Target version changed from 3.6.7 to 3.7.1+
Updated by Jörg Riesmeier over 1 year ago
- Subject changed from OFVector needs to seperate allocation and element construction to OFVector needs to separate allocation and element construction
Actions