Newsgroups: comp.lang.dylan,comp.lang.misc,comp.lang.lisp,comp.object,comp.arch
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!oitnews.harvard.edu!purdue!lerc.nasa.gov!magnus.acs.ohio-state.edu!math.ohio-state.edu!howland.reston.ans.net!tank.news.pipex.net!pipex!dish.news.pipex.net!pipex!logica.co.uk!NewsWatcher!user
From: justin@logcam.co.uk (Justin Forder)
Subject: Re: allocator and GC locality (was Re: cost of malloc)
X-Nntp-Posting-Host: 158.234.26.212
Message-ID: <justin-0108951458440001@158.234.26.212>
Sender: news@carmen.logica.co.uk (News Manager Account)
Organization: Logica UK Ltd.
References: <9507261647.AA14556@aruba.apple.com> <3v8g7l$cge@jive.cs.utexas.edu> <3vac07$ptf@info.epfl.ch> <3vb382$dtr@jive.cs.utexas.edu> <3vbl70$bht@fido.asd.sgi.com> <hbaker-3107951026250001@192.0.2.1>
Date: Tue, 1 Aug 1995 13:58:44 GMT
Lines: 59
Xref: glinda.oz.cs.cmu.edu comp.lang.dylan:4934 comp.lang.misc:22426 comp.lang.lisp:18499 comp.object:36110 comp.arch:60020

In article <hbaker-3107951026250001@192.0.2.1>, hbaker@netcom.com (Henry
Baker) wrote:

[snip]

> My own pet peeve is _weak_ language type systems like Ada and C++ that
> _force_ you to break apart a single object into a number of smaller subobjects
> _that are separately mallocated_ even when you know how to manage the
> object as one object in assembly language.  Stroustrup's C++ is especially
> 'pointer-happy', as a perusal of the following two books will show:
> 
> Stroustrup, Bjarne.  "The C++ Programming Language, Second Edition".  Addison
> Wesley, 1991.
> 
> Ellis, M.A. and Stroustrup, B.  "The Annotated C++ Reference Manual".
> Addison Wesley, 1990.
> 
> Whenever things get tough, C++ wimps out and forces another pointer
indirection.
> 
> Of course, this 'solves' the problem for the C++ implementor, but throws
> a much larger problem over the fence onto the poor application writer
> and/or memory manager, who is now forced to deal with a much higher load
> of smaller objects.
> 
> Whoever said that C++ doesn't force you to pay for features you don't use
> hasn't ever programmed in C++ to any extent.

I'm puzzled - in C++, using a pointer is the price you pay for polymorphism.

The design space for C++ classes has two "safe corners":

1) for user-defined data types, with value semantics and no inheritance
   or virtual member functions, and with the relevant operators defined
   to make them well-behaved C++ data types,

2) the other for object-oriented programming, with inheritance, virtual 
   member functions and destructors (and possibly protection
   against copying or assignment).

These are Coplien's two "canonical class forms". Objects of the first kind
(values) normally live on the stack or are directly embedded in larger objects.
Objects of the second kind (instances) normally live on the heap, and give
rise to all the memory management problems.

Things get more interesting when you move into the middle of the design space,
or produce hybrid approaches (e.g. for large values with copy-on-write, or
as with the many kinds of smart pointers).

You are right to say that C++ throws a large problem over to application
writers, but by doing this it does allow a great variety of solutions, and
once you have chosen a solution it is often possible to package it in a way
that can be used easily and concisely.

   Justin

-- 
Justin Forder                               justin@logcam.co.uk
Logica, Stephenson House, 75 Hampstead Road, London NW1 2PL, UK
