Further observations regarding alloca on i586-pc-linux-gnu

Martin von Loewis martin@mira.isdn.cs.tu-berlin.de
Tue Aug 25 19:31:00 GMT 1998


> 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.

You did not say how long you need the memory: If you need automatic
deallocation when the caller of f returns, you can return an auto_ptr
from f.

> Will do. Does it kill every built in function or is it possible to
> target a specific one?

Have a look at the manual. It will consider no function builtin,
unless you explicitly invoke, say, __builtin_memcpy.

Regards,
Martin



More information about the Gcc mailing list