Newsgroups: comp.lang.dylan,comp.lang.misc,comp.lang.lisp,comp.object,comp.arch,comp.lang.c++
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!gatech!howland.reston.ans.net!xlink.net!slsv6bt!news
From: kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763)
Subject: Re: allocator and GC locality (was Re: cost of malloc)
In-Reply-To: "Stefan Monnier"'s message of 17 Aug 1995 13:41:24 GMT
Message-ID: <KANZE.95Aug18133802@slsvhdt.lts.sel.alcatel.de>
Lines: 37
Sender: news@lts.sel.alcatel.de
Organization: SEL
References: <9507261647.AA14556@aruba.apple.com>
	<KANZE.95Aug16203305@slsvhdt.lts.sel.alcatel.de>
	<40up1a$s6q@info.epfl.ch>
	<KANZE.95Aug17141818@slsvhdt.lts.sel.alcatel.de>
	<40vgu4$73r@info.epfl.ch>
Date: 18 Aug 1995 11:37:59 GMT
Xref: glinda.oz.cs.cmu.edu comp.lang.dylan:5089 comp.lang.misc:22748 comp.lang.lisp:18829 comp.object:37022 comp.arch:60516 comp.lang.c++:144630

In article <40vgu4$73r@info.epfl.ch> "Stefan Monnier"
<stefan.monnier@epfl.ch> writes:

|> In article <KANZE.95Aug17141818@slsvhdt.lts.sel.alcatel.de>,
|> James Kanze US/ESC 60/3/141 #40763 <kanze@lts.sel.alcatel.de> wrote:
|> ] I sort of agree.  Still, the string class will have to manage the
|> ] memory for the flat representation as well.

|> Big deal: malloc the thing, return the pointer and document the fact that
|> whenever the string is not useful any more, it has to be freed by "delete".

Not acceptable.  Obtain the memory through new, and document under
which cases the string class frees it.

Note that its most frequent use will be:

	extern "C" void     f( char const* s ) ;
	string              s ;

	f( s.c_str() ) ;

It's hardly likely that `f' will free it (since in other contexts, `f'
will be called with e.g.: a string literal), and you don't want to
hassle having to maintain a pointer yourself.

In the case of the standard string class, it is already documented
when the pointer returned by c_str becomes invalid.  So you know
exactly when you can free it.  (If memory serves me right, it is until
the next non-const function is called on the string, or the
destructor.)
-- 
James Kanze         Tel.: (+33) 88 14 49 00        email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils en informatique industrielle --
                              -- Beratung in industrieller Datenverarbeitung


