Project

General

Profile

Actions

Bug #758

open

OFVector needs to separate allocation and element construction

Added by Jan Schlamelcher about 8 years ago. Updated over 1 year ago.

Status:
New
Priority:
Normal
Category:
-
Target version:
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() == 10
means 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.

Actions #1

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.

Actions #2

Updated by Marco Eichelberg over 7 years ago

  • Assignee set to Nikolas Goldhammer
Actions #3

Updated by Jan Schlamelcher over 7 years ago

  • Target version changed from 3.6.3 to 3.6.6
Actions #4

Updated by Michael Onken over 5 years ago

  • Target version deleted (3.6.6)
Actions #5

Updated by Michael Onken over 5 years ago

  • Target version set to 3.6.6
Actions #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
Actions #7

Updated by Michael Onken over 3 years ago

  • Target version changed from 3.6.7 to 3.7.1+
Actions #8

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

Also available in: Atom PDF