• 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
Potential trick for adding instance variables to classes using poseAs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Potential trick for adding instance variables to classes using poseAs


  • Subject: Potential trick for adding instance variables to classes using poseAs
  • From: Wade Tregaskis <email@hidden>
  • Date: Sat, 20 Nov 2004 00:44:21 +1100

Forward Disclaimer:  this is all nasty business.  No whinging. :P

I've just been playing with poseAs: for a class I don't have a complete definition for - it contains some anonymous struct I don't know the size of... if I commented this out to get it compile, I noticed then that when I substituted my poser for the real class, there was memory corruption resulting from the existing class writing past it's end - which is a result of my substitute thinking it's shorter than it really is. Aha, I say...

So, after fixing this particular case (the magic number was 4 bytes in this case, fwiw; in the AddressAttachmentCell in Mail) I had the thought - I can adjust how much memory is allocated for a class just by modifying it's header. Now, this requires that the header be editable by you - in my case Mail doesn't have any headers, so I'm using those from class-dump. No conflict, obviously. I imagine you could extend this by copying published headers from frameworks and importing your local, modified copies instead.

And more than just increasing the size, you can add in your items by name as you would normally, and access them like normal. Fantastic! :)

At least, it seems so, so far... I'm thinking this might give some real headaches if a subclass of the class you're posing as defines it's own instance variables too... ick. Still, it seems like it could work in very controlled cases. I thought I'd share this for objective criticism and general interest. No flaming, please - refer to the disclaimer. :)

Wade Tregaskis (AIM, Yahoo & Skype: wadetregaskis, ICQ: 40056898, MSN & email: email@hidden, Jabber: email@hidden)
-- Sed quis custodiet ipsos custodes?


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Potential trick for adding instance variables to classes using poseAs
      • From: Glenn Andreas <email@hidden>
  • Prev by Date: Resize Window with fixed ratio
  • Next by Date: Re: Fastest way to push strings to the screen in an NSView?
  • Previous by thread: Re: Resize Window with fixed ratio
  • Next by thread: Re: Potential trick for adding instance variables to classes using poseAs
  • Index(es):
    • Date
    • Thread