🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #4070

Re: Just one more library function

#4070
From: Jason Merrill
Date: Wed, 17 Apr 1996 08:49
25 lines
1771 bytes
>>>>> Igor Boukanov <Igor.Boukanov@fi.uib.no> writes:

> Why do not require that every C++ implementation should provide function
> that will return for the pointer obtained from new[] the number of 
> allocated elements, i.e. something like:

> template<class T> size_t array_allocation_size(T* p);

> So for 'int* p = new int[3];' 'array_allocation_size(p)' will return 3.

> Such function will be very easy to implement because in the case of
> delete[] compiler use something like this.

Not necessarily.  For instance, g++ only stores the number of elements if 

1) The element type has a destructor, or
2) The element type has an operator delete that takes the size_t argument.

Jason
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
Technical Details
Message-ID: <u93f63214o.fsf@yorick.cygnus.com>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
References: <Pine.HPP.3.91.960416133333.19297A-100000@hadron.fi.uib.no>

Show Full Headers
Complete Article Headers
From: jason@cygnus.com (Jason Merrill)
Message-ID: <u93f63214o.fsf@yorick.cygnus.com>
X-Original-Date: 16 Apr 1996 16:35:35 -0700
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
Date: 17 Apr 96 08:49:00 GMT
Approved: fjh@cs.mu.oz.au
Newsgroups: comp.std.c++
Subject: Re: Just one more library function
Organization: Cygnus Support, Mountain View, CA
References: <Pine.HPP.3.91.960416133333.19297A-100000@hadron.fi.uib.no>
In-Reply-To: Igor Boukanov's message of 16 Apr 1996 13:15:25 PDT
X-Newsreader: Gnus v5.0
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMXSwluEDnX0m9pzZAQFSKAF/eQj/ntLuT9R9kmR4uCjP/mXtfa436RiL
 YXZXPBecWeVlQxAINDOw9LWD9RAmezkq
 =qZG4