This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Placement new[] weirdness


Hi,

We have the following in C++ draft, clause 5.3.4:

12[Example:
  
  --new T results in a call of operator new(sizeof(T)),
  
  --new(2,f) T results in a call of operator new(sizeof(T),2,f),
  
  --new T[5] results in a call of operator new[](sizeof(T)*5+x), and
  
  --new(2,f) T[5]        results        in        a        call       of
    operator new[](sizeof(T)*5+y,2,f).
  
  Here, x and y are non-negative, implementation-defined  values  repre-
  senting  array  allocation  overhead.  Their value might vary from one
  invocation of new to another.  ]
  
This means that a call of placement new[] operator
  new(p) T[N];
returns p+x, where x is some implementation-defined constant.
This makes placement new[] operator totally useless.

>From the other point, in C++ draft, clause 18.4.1.3:

  void* operator new[](std::size_t size, void* ptr) throw(); 
  
  Returns:
    ptr.
  Notes:
    Intentionally performs no other action.


I.e. this contradicts to the previous description.

Can anybody check the final standard about this?

Indeed, I can imagine a correct implementation of placement new[]
which has zero overhead for array length (though such implementation
may have perfomance loss).

Regards,
Andrey.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]