Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Resource acquisition is initialization
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: David Brown <caml-list@d...>
Subject: Re: [Caml-list] Resource acquisition is initialization
On Fri, Dec 13, 2002 at 12:22:16PM +0300, Mike Potanin wrote:

> > char * foo(...) {
> >     char buf[];
> >     /* do something to fill buf */
> >     return buf;
> > }
> >
> > This sounds like a wonderful way to introduce dangling pointer bugs in the
> > language.

> Cyclone language handle this problec staticaly (compile time). It no need
> GC use.

Numerous languages handle this kind of construct.  Often, though, you
end up having to copy the result when you return.  However, they
wouldn't handle it if the function was defined to return a pointer.
Instead, however, they let functions return larger objects (such as
arrays).

Usually they are implemented with a secondary stack to hold these
values.

I suspect, though, that the additional copying that ends up happening
with the technique ends up being as, or more, expensive than Ocaml's
garbage collector, especially if the data doesn't live long and doesn't
survive the young area.

Dave Brown
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners