[Gllug] C++ Templates, Opinions?
Richard Jones
rich at annexia.org
Mon Dec 20 12:22:53 UTC 2004
On Mon, Dec 20, 2004 at 12:10:42PM +0000, Ian Norton-Badrul wrote:
> Richard Jones wrote:
> ~ > http://www.cuj.com/documents/s=7994/cujcexp1906alexandr/alexandr.htm
> |
> | You've got to love these C++ programmers. They're STILL
> | reimplementing a string class, badly!
> |
> | There are languages available right now, that - would you believe it? -
> | already have strings.
> |
> | Perhaps one day, once they've finished strings, they'll be able to do,
> | oh, I don't know, garbage collection, or regular expressions, or
> | bounds checking, and actually make the language useful for something ...
>
> A good programmer doesnt need automatic garbage collection :-)
> sureley free() is enough ;-)
:-)
The real problem with malloc/free is that they're slooowwwww. Yes,
really, they're slower than automatic garbage collection[1].
In OCaml, the common path for allocations is 6 machine instructions
(sic!). That's about a nanosecond on a modern processor. Dealloc-
ation takes place all at once (in the garbage collector) resulting in
excellent temporal locality, which means good use of the cache.
Compare to calling free() all over your code, and the big data
structures which free must traverse. It's much better to do this all
in one place, so that you get the benefit of your L1 cache.
Now I'm not saying that it's impossible to hand-optimise malloc and
free so they do better than a garbage collector, but it requires a
huge amount of effort. Would you write every program in assembler?
I won't even get started on the programmer time saved by not having to
track down memory-related bugs.
Rich.
[1] Two things have given GC a bad name: Java and Emacs. They are not
representative of good, modern garbage collectors.
--
Richard Jones. http://www.annexia.org/ http://www.j-london.com/
>>> http://www.team-notepad.com/ - collaboration tools for teams <<<
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
http://youunlimited.co.uk/ - Personal improvement courses
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: Digital signature
URL: <http://mailman.lug.org.uk/pipermail/gllug/attachments/20041220/9743b973/attachment.pgp>
-------------- next part --------------
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list