Topic: Value of size parameter to operator [] not specified in standard.
Author: "rich_sposato" <rds@richsposato.com>
Date: 7 Aug 2005 01:30:01 GMT Raw View
I checked the C++ Standard to see if it requires a value for the size
parameter to operator delete []. Nothing I found in sections 5.3.5,
3.7.3.2, or 18.4.1.2 specifies what is passed into the size parameter
for
void operator delete [] ( void * place, std::size_t size ) throw ();
There is enough variation among compilers when providing a value for
the size parameter that I can't write a simple, safe, and portable
operator delete [] for the Loki library.
For example:
GCC 3.4.2 makes size = ( sizeof(T) * count ) + delta.
MSVC 7.1 makes size = sizeof(T).
Of course, the count is the number of T objects in the array, and delta
is the size in bytes of any compiler overhead.
(I also checked what values are passed into the single object form of
operator delete. All the compilers passed in sizeof(T).)
I would like the ISO C++ Committee to make one small refinement to the
standard so that all compilers pass in the same size value to operator
delete [].
Here is my suggested wording:
3.7.3.2 Deallocation functions
[basic.stc.dynamic.deallocation]
Amend this sentence in paragraph 2 to read as follows. (All I did was
add the final clause to the sentence. The rest remains identical to
what is in the standard already.)
"If class T does not declare such an operator delete [] but does
declare a member deallocation function named operator delete [] with
exactly two parameters, the second of which has type std::size_t, then
this function is a usual deallocation function, and the value for the
std::size_t parameter shall be identical to the value passed into the
"void * new [] (std::size_t size )" when the memory was allocated.
(See Section 5.3.4.12)"
If anybody thinks I missed something or suspects that a different
wording would be better, feel free to make a suggestion.
Thanks.
Rich Sposato
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: "rich_sposato" <rds@richsposato.com>
Date: Sun, 7 Aug 2005 14:50:38 CST Raw View
Correction:
Summary of this entry is:
Value of size parameter to operator [] not specified in standard.
It should be:
Value of size parameter to operator delete [] not specified in
standard.
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: squell@alumina.nl (Marc Schoolderman)
Date: Sun, 7 Aug 2005 21:32:25 GMT Raw View
rich_sposato wrote:
> I would like the ISO C++ Committee to make one small refinement to the
> standard so that all compilers pass in the same size value to operator
> delete [].
I think the paragraph you are looking for is 12.5/5. Seems to me you
found a bug in MSVC.
~Marc.
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: "rich_sposato" <rds@richsposato.com>
Date: 8 Aug 2005 05:20:01 GMT Raw View
Marc wrote:
> I think the paragraph you are looking for is 12.5/5.
Got it. Thanks.
> Seems to me you found a bug in MSVC.
Yep, and that's not the only one I found in MSVC.
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]