Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!crackers!jjmhome!smds!rh From: rh@smds.UUCP (Richard Harter) Newsgroups: comp.lang.c Subject: Re: Just rambling about optimization... Summary: Improper modularization Message-ID: <459@smds.UUCP> Date: 12 May 91 07:39:48 GMT References: <444@smds.UUCP> <186@shasta.Stanford.EDU> <721@taumet.com> <13089@dog.ee.lbl.gov> Organization: SMDS Inc., Concord, MA Lines: 34 In article <13089@dog.ee.lbl.gov>, torek@elf.ee.lbl.gov (Chris Torek) writes: > Indeed. It has been observed (sorry, no references, but this is not > only popularly known but also true :-) ) that many computers spend most > of their time copying data, rather than `computing'. This is largely > why a fast bcopy/memcpy/memmove is important. A fast block copy is > a wonderful thing, but better yet is to eliminate the copies altogether. True enough. One of the traps in construction of large software is that when one breaks up into components there is a real tendency copy data from component to component as a matter of convenience. For example suppose we have components A, B, and C with data flowing from A to B to C. The easy way to deal with this is to make each component its own source and sink. I.e. A creates a data set, passes it to B, and then disposes of it after B is completed. B copies its input into its own area, passes its processed data to C, and then disposes of it, and C does the same thing. Stated this baldly, it is clear that A should be the source, C the sink, and nobody should copy. However, if we look at the general case, A, B, C, etc will be defined and implemented independently, i.e. modularly. If each module has responsibility for creating and disposing of its own data then inter-module coupling is minimized and there are no nasty questions about who disposes of what. Which, of course, is why it pays to use object-oriented techniques even in non OO languages. In this case it would pay to package the data set with a reference count and a module of data-set methods. Each user ups the count upon access and decrements upon dispose. When the count goes to 0 the actual physical disposition is done. [Operations hidden behind macro or function calls, of course.] -- Richard Harter, Software Maintenance and Development Systems, Inc. Net address: jjmhome!smds!rh Phone: 508-369-7398 US Mail: SMDS Inc., PO Box 555, Concord MA 01742 This sentence no verb. This sentence short. This signature done.