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

Also available in: Atom PDF