Re: NSPoint. The results. Look at that, Georg!
Re: NSPoint. The results. Look at that, Georg!
- Subject: Re: NSPoint. The results. Look at that, Georg!
- From: Sherm Pendley <email@hidden>
- Date: Mon, 3 Mar 2003 09:28:56 -0500
On Monday, March 3, 2003, at 08:23 AM, Pascal Goguey wrote:
I made all the experiments in C++
Which, unfortunately for the rest of your argument, makes them
completely invalid with respect to Objective-C. An Objective-C message
and a C++ method, while similar in concept, are *completely* different
in implementation.
A method call in C++ is basically just a function call - most of the
indirection involved is resolved at compile time. What happens at run
time is simply an indirect call to a function via a pointer found in a
vtable. It's not really all that different from a plain C function call.
In Objective-C, the runtime finds the address of the method that handles
a message by looking up the selector in a hash table - it caches the
results, and it's very efficient, but even so, it does take a few more
cycles than C++'s tightly-bound direct method calls. This small amount
of overhead is negligible for most purposes, but for objects that may
need to be messaged thousands or even millions of times, it adds up.
In C++, the space of an object is not bigger if it is a class rather
than if it is a structure.
That's hardly a surprise, since an instance of a class is basically just
the struct that holds its instance variables.
Unfortunately, comparing the size of a single instance doesn't take into
account the space (or time) used by the additional methods needed to
access an object's instance variables. If you're using a struct, you can
get a point's X coordinate with a simple myPoint.x; if it were an
object, you'd need to implement a getX() method. That method will *not*
take zero bytes, and it most certainly will not execute as quickly as
direct access to the struct member x.
why are some NS objects only structures while others are classes?
Why are many simple variable types - int, float, BOOL, pointers -
declared as such? Because OOP, like many things that can be beneficial
when taken in moderation, can be harmful when taken to absurd lengths.
Not everything *needs* to be an object.
sherm--
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.