swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

WorkingExampleCode divided among C, Objc, and Java


From: Paul Johnson
Subject: WorkingExampleCode divided among C, Objc, and Java
Date: Fri, 17 Dec 1999 10:56:34 -0600

I'm eagerly preparing for a course next spring and the first thing I
have to do is teach C.  Then Swarm.

Anyway, while working on this, I decided to take the WorkingExampleCode
section of SwarmFaq and divide it among c, objc, and java.  The latter
two are restricted to swarm stuff, and almost all examples are by Marcus
Daniels.  I need to prepare a readme file for usage to remind people how
to compile these things.

http://lark.cc.ukans.edu/~pauljohn/SwarmFaq/WorkingExampleCode
now has subdirs
c
objc
java

In the c directory, you will find an interesting piece of code I found
in the Gnome discussion list.  A fellow named Jim Gettys has been
correcting various mistakes people are making in the optimization of
code.  For example, here is one point he made that I found quite
striking:

___________
>From Jim Gettys

> From: Havoc Pennington <address@hidden>

> 
> Keep in mind that there is almost always a size/speed tradeoff. That is,
> we can almost always make things faster by using more memory - assuming
> you have the memory to use. :-) So there is some cost to making things too
> small.
> 

I have to call you on this one:

Since the early 90's, on RISC systems, and since about 1995 on Intel,
your
code runs faster if it is SMALLER.

Using more memory almost always makes things SLOWER on current systems.

Memory bandwidth is, as a general rule, much more precious than
instructions.
Getting that data structure into a cache line can make a major
performance
difference.

Even in 1990 or so, we made the X server MUCH faster while
simultaneously
reducing its memory usage in data structures to 40% of the first release
of X version 11.
______________
He went on with some evidence, I don't know if today's faster RAM
changes his result.

Anyway, he posted another note that had an example C program that shows
the amount of Memory that a struct uses can be dramatically affected by
the order in which the variables are added.  The effect has to do with
alignment and the compiler's tendency to align larger items in a way
that does not make the most efficient use of the space.  The point: to
reduce memory usage, you should always include items in a structure from
smallest (in bits) to largest.  Here is his note and an example program:

http://lark.cc.ukans.edu/~pauljohn/SwarmFaq/WorkingExampleCode/c/ExamineRamUsage.txt

What does this have to do with swarm?  My understanding is that the objc
compiler basically treats objc classes as if they were structs. 
Wouldn't the same thing that makes a struct use more memory also affect
an objc class?


-- 
Paul E. Johnson                       email: address@hidden
Dept. of Political Science            http://lark.cc.ukans.edu/~pauljohn
University of Kansas                  Office: (785) 864-9086
Lawrence, Kansas 66045                FAX: (785) 864-5700

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]