• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSPoint. The results. Look at that, Georg!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >NSPoint. The results. Look at that, Georg! (From: Pascal Goguey <email@hidden>)

  • Prev by Date: NSPoint. The results. Look at that, Georg!
  • Next by Date: Re: NSPoint. The results. Look at that, Georg!
  • Previous by thread: NSPoint. The results. Look at that, Georg!
  • Next by thread: Re: NSPoint. The results. Look at that, Georg!
  • Index(es):
    • Date
    • Thread