Length of C++ arrays allocated by operator new[]

N

Noah Roberts

The length of the allocated array must be stored somewhere
by new so that delete[] knows how many destructors to call.
But theres no standard way to get this length.

That is not completely correct. You can override the new operator to
use an allocator that will provide you with that information. This
would all indeed be quite within the standard. It is also, of course,
why there can never be a *generic* method of accessing this
information.
 
B

Bo Persson

Gerald said:
The length of the allocated array must be stored somewhere
by new so that delete[] knows how many destructors to call.
But theres no standard way to get this length.

So the standard decided to provide std::vector instead of trying to
fix the broken C style arrays.


Bo Persson
 
G

Gerald Breuer

Am 28.08.2011 16:38, schrieb Bo Persson:
So the standard decided to provide std::vector instead of trying to
fix the broken C style arrays.

There's nothing broken with C style arrays.
 
B

Bo Persson

Gerald said:
Am 28.08.2011 16:38, schrieb Bo Persson:


There's nothing broken with C style arrays.

Right, except that people try to determine their length?


Bo Persson
 
G

Gerald Breuer

Am 28.08.2011 22:44, schrieb Bo Persson:
Right, except that people try to determine their length?

A missing functionality doesn't make something broken.
 
J

James Kanze

Am 28.08.2011 16:38, schrieb Bo Persson:
There's nothing broken with C style arrays.

Except that they're not first class types. C uses value
semantics for objects (C++ too, by default). Except when the
object is an array, in which case, there is an implicit
conversion to an unrelated type (except when there isn't).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top