• 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: How do I create a mutable version of my object?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I create a mutable version of my object?


  • Subject: Re: How do I create a mutable version of my object?
  • From: Jens Bauer <email@hidden>
  • Date: Tue, 21 Jan 2003 04:29:21 +0100

Hi Chris,

On Monday, Jan 20, 2003, at 23:34 Europe/Copenhagen, Chris Hanson wrote:

At 8:15 PM +0100 1/20/03, Jens Bauer wrote:
I'm afraid of the overhead of NSObject. If it contains too many instance-variables, then it'll quickly grow huge. On the other hand, if NSObject already knows how to "repeat" a subclass (which I think might be difficult for NSObject), it would only add the overhead >> once.

Uh, what? It sounds like you're doing *very* premature optimization here *and* you don't understand how classes and instances are implemented in Objective-C.

Indeed no. :)

An instance of NSObject currently has a single instance variable, isa, that points to the object's class.

OK, a pointer that is 4 bytes in size, I believe. Acknowledged.

Any instance of a subclass Foo of NSObject will have that instance variable,

Acknowledged. Clear to me, just like C++ and what I would expect from inheritance.

as well as any instance variables defined by Foo.

Acknowledged, makes sense.

Any instance of a subclass Bar of Foo will have isa from NSObject, any instance variables defined by Foo, and any instance variables defined by Bar.

Yes, clear!

-But... In a class, you can make some pretty nice tricks sometimes, in accessor-functions, that makes arrays behave differently, so that you do not see what's going on inside the class, you just use it, and something completely different happens, than what you would normally think.
Right now, I'm talking operator-overload-talk, as you probably know about.
It can be difficult (and completely transparant to the user), whether the array-class has 32 pointers to each object, or a cluster of 32 indexed objects, you see what I mean?
It'd also be possible, I bet, to write a method, that just creates/returns a pseudo-object, where the base-object is excluded. (This would be to save memory, but I believe it's not the case with NSArray and NSObject, as this could be real messy.)

There are two things you need to do:

(1) Read "The Objective-C Programming Language" in the developer documentation, so you understand the Objective-C language, both how to use it and how it works behind the scenes.

I'll go and see if I can get some holes filled. ;)

(2) Remember the rules of optimization: Get the code working 100%, determine if performance needs improving, then *measure* where your performance is going and address the areas your *measurement* indicates in priority order.

If I need to get the code working 100% first, then I'll write it in C, and then there's no need to optimize it, because I write well-optimized C.
What I'm really trying to do, is to get a recipe on how to make mutable objects, both for my own use, currently 1 case, but also for others, and I'd like to put it up on objc-source.org, when I've done some polishing... ;)


Love,
Jens
_______________________________________________
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: 
 >Re: How do I create a mutable version of my object? (From: Chris Hanson <email@hidden>)

  • Prev by Date: Re: Leaking Memory
  • Next by Date: Re: Leaking Memory
  • Previous by thread: Re: How do I create a mutable version of my object?
  • Next by thread: Re: How do I create a mutable version of my object?
  • Index(es):
    • Date
    • Thread