This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Further observations regarding alloca on i586-pc-linux-gnu
- To: egcs at cygnus dot com
- Subject: Re: Further observations regarding alloca on i586-pc-linux-gnu
- From: Oleg Zabluda <zabluda at math dot psu dot edu>
- Date: Wed, 26 Aug 1998 12:35:14 -0400 (EDT)
- Organization: Penn State University, Center for Academic Computing
- Reply-To: zabluda at math dot psu dot edu (Oleg Zabluda)
In article <199808250624.IAA00271@mira.isdn.cs.tu-berlin.de> you wrote:
: > a) allocate heap memory inside the function. Disadvantage: needs
: > explicite release.
: I'd say auto_ptrs are there for you, no? Somebody correct me, but it
: seems that
: void f(char * = std::auto_ptr<char*>(new char[20]));
: is valid C++, and gives you memory that will live slightly longer than
: the call to f, and will then be automatically deallocated.
This needs some modifications:
1. auto_ptr<>'s destructor deallocates the memory with
operator delete, while you will need operator delete[].
So you'll have to use your own auto_array<> or something,
with the correct destructor.
2. My understanding is that the default arguments have static
storage duration. This is not what was intended.
3. You can not initialize ``char*'' with std::auto_ptr<char*>.
I think this is a typo. You meant something similar to
void f( char* = std::auto_ptr<void*>(::operator new(20)).get() );
Oleg.