"A failure in the hot air department"
Showing entries tagged "objectivec". Full blog index.
accessors(2) arc(4) assembly(4) assert autorelease(2) blocks(5) bug c(4) c++(2) chemicalburn clang(2) cocoa(19) code(2) continuation continuations defensive disassembly(3) enumeration errorhandling evil(4) fridayqa fridayqna(48) garbagecollection guest(3) hack(8) hash init initializer iphone(2) isequal leopard(2) letsbuild(10) memory(3) nscoding nsfastenumeration objectivec(64) override performance(5) pyobjc python rant serialization singleton sourcecode(2) stl super swizzling threading(3) translation vararg
Friday Q&A 2017-06-30: Dissecting objc_msgSend on ARM64 at 2017-07-01 04:23
We're back! During the week of WWDC, I spoke at CocoaConf Next Door, and one of my talks involved a dissection of
objc_msgSend's ARM64 implementation. I thought that turning it into an article would make for a nice return to blogging for Friday Q&A.
Friday Q&A 2016-04-15: Performance Comparisons of Common Operations, 2016 Edition at 2016-04-15 13:20
Back in the mists of time, before Friday Q&A was a thing, I posted some articles running performance tests on common operations and discussing the results. The most recent one was from 2008, running on 10.5 and the original iPhone OS, and it's long past time to do an update.
Friday Q&A 2015-07-31: Tagged Pointer Strings at 2015-07-31 14:10
Tagged pointers are an interesting technology used to increase performance and reduce memory usage. As of OS X 10.10,
NSStringgot the tagged pointer treatment, and today I'm going to take a look at how it works, a topic suggested by Ken Ferry.
Friday Q&A 2015-05-29: Concurrent Memory Deallocation in the Objective-C Runtime at 2015-06-05 13:06
The Objective-C runtime is at the heart of much Mac and iOS code. At the heart of the runtime is the
objc_msgSendfunction, and the heart of that is the method cache. Today I'm going to explore how Apple manages resizing and deallocating method cache memory in a thread safe manner without impacting performance, using a technique you probably won't find in textbooks discussing thread safety.
Friday Q&A 2013-10-25: NSObject: the Class and the Protocol at 2013-10-25 13:27
Reader Tomas Bouda asks: what's the deal with the
NSObjectprotocol? There are two
NSObjectsin Cocoa, a class and a protocol. Why both? What purpose do they serve? In today's article, I'll explore the answer to this question.
Friday Q&A 2013-05-17: Let's Build stringWithFormat: at 2013-05-17 14:40
Our long effort to rebuild Cocoa piece by piece continues. For today, reader Nate Heagy has suggested building
Friday Q&A 2013-05-03: Proper Use of Asserts at 2013-05-03 13:03
Asserts are a powerful tool for building quality code, but they're often poorly understood. Today, I want to discuss the various options for writing asserts in Cocoa apps and the best ways to use them, a topic suggested by reader Ed Wynne.
Objective-C Literals in Serbo-Croatian at 2013-03-26 23:48
Reader Anja Skrba from Webhostinggeeks.com has translated my Objective-C Literals article into Serbo-Croatian. It's always fun to see translations of my writing, even when I can't understand them at all. If you do understand Serbo-Croatian, or know someone who does, check it out. The Serbo-Croatian version of Objective-C Literals is available on Webhostinggeeks.com.
Friday Q&A 2013-03-22: Let's Build NSInvocation, Part II at 2013-03-22 14:57
Last time on Friday Q&A, I began the reimplementation of parts of
MAInvocation. In that article, I discussed the basic theory, the architecture calling conventions, and presented the assembly language glue code needed for the implementation. Today, I present the Objective-C part of
Friday Q&A 2013-03-08: Let's Build NSInvocation, Part I at 2013-03-08 14:33
It's time for another trip into the nether regions of the soul. Reader Robby Walker suggested an article about
NSInvocation, and I have obliged, implementing it from scratch for your amusement. Today I'll start on a guided tour down the hall of horrors that is
MAInvocation, my reimplementation of the
NSInvocationAPI. It's a big project, so today I'm going to focus on the basic principles and the assembly language glue code, with the rest of the implementation to follow.
Friday Q&A 2013-02-08: Let's Build Key-Value Coding at 2013-02-08 14:17
Last time, I showed how to build the basic functionality of
NSObject. I left out key-value coding, because the implementation of
setValue:forKey:is complex enough to need its own article. This is that article.
Friday Q&A 2013-01-25: Let's Build NSObject at 2013-01-25 15:32
NSObjectclass lies at the root of (almost) all classes we build and use as part of Cocoa programming. What does it actually do, though, and how does it do it? Today, I'm going to rebuild
NSObjectfrom scratch, as suggested by friend of the blog and occasional guest author Gwynne Raskind.
Friday Q&A 2012-12-14: Objective-C Pitfalls at 2012-12-14 14:38
Objective-C is a powerful and extremely useful language, but it's also a bit dangerous. For today's article, my colleague Chris Denter suggested that I talk about pitfalls in Objective-C and Cocoa, inspired by Cay S. Horstmann's article on C++ pitfalls.
Friday Q&A 2012-11-16: Let's Build objc_msgSend at 2012-11-16 14:27
objc_msgSendfunction underlies everything we do in Objective-C. Gwynne Raskind, reader and occasional Friday Q&A guest contributor, suggested that I talk about how
objc_msgSendworks on the inside. What better way to understand how something works than to build it from scratch? Let's build
Friday Q&A 2012-07-27: Let's Build Tagged Pointers at 2012-07-27 13:35
Last time on Friday Q&A, I discussed a hypothetical implementation of the
NSNumberclass. Starting on Mac OS X 10.7 and iOS 5,
NSNumberuses a new runtime facility called tagged pointers to increase speed and reduce memory usage, the inner workings of which I want to examine today.
Friday Q&A 2012-07-06: Let's Build NSNumber at 2012-07-06 15:08
NSNumberis a deceptively simple class with some interesting implementation details. In today's edition of Friday Q&A, I'll explore how to build a class that works like
NSNumber, a topic suggested by Jay Tamboli.
Friday Q&A 2012-06-22: Objective-C Literals at 2012-06-22 14:17
Welcome back! After a brief hiatus for WWDC, it's time for another wacky adventure. Today's topic is the new object literals syntax being introduced into Objective-C, which was suggested by reader Frank McAuley.
Friday Q&A 2012-06-01: A Tour of PLWeakCompatibility: Part II at 2012-06-01 13:38
Last time, I discussed the basics of PLWeakCompatibility in terms of the motivation, the basic hooks used to get the compiler to call our code when handling
__weakvariables, and calling through to the original implementations where available. Today, I'm going to discuss the implementation of the zeroing weak reference facility that gets used when the runtime doesn't supply its own
Friday Q&A 2012-05-18: A Tour of PLWeakCompatibility: Part I at 2012-05-18 16:53
A few weeks ago, I introduced
PLWeakCompatibility. This is a small library that can be dropped into an app to enable use of the
__weakqualifier on OSes that don't support it. ARC is officially supported on Mac OS X 10.6 and iOS 4, but
__weakis only available on 10.7 and iOS 5.
PLWeakCompatibilityadds support for
__weakon those older OSes when using ARC. Today I'm going to discuss how
PLWeakCompatibilityworks on the inside.
Introducing PLWeakCompatibility at 2012-03-31 03:09
As a way of atoning for the lack of a Friday Q&A today, I'm pleased to introduce PLWeakCompatibility. Do you like ARC? Do you need to support older OS releases? Do you wish you could use
__weakvariables on those older OSes? If so, then I have good news for you! PLWeakCompatibility is the solution you've been looking for.
Friday Q&A 2012-03-16: Let's Build NSMutableDictionary at 2012-03-16 14:55
Last time on Friday Q&A, we discussed how to implement
NSMutableArray. Today, I'll repeat the same exercise with
NSMutableDictionaryand build an implementation of it from scratch.
Friday Q&A 2012-03-09: Let's Build NSMutableArray at 2012-03-09 13:44
Collection classes are ubiquitous in Cocoa apps, but also fairly opaque. Today, at the suggestion of Matthew Elton, I'm going to take a look at how
NSMutableArrayworks behind the scenes by building a replacement for it from scratch.
Deadlocks and Lock Ordering: a Vignette at 2012-02-13 04:26
Every once in a while, when writing threaded code, you may find yourself wanting to acquire two different locks in a critical section. Normally one should resist such perversions, but sometimes they just end up being necessary, or too tempting. Holding multiple locks at the same time immediately raises the specter of deadlock: if two threads acquire the same locks in a different order, they can end up waiting on each other forever.
Friday Q&A 2012-01-06: The Hopper Disassembler at 2012-01-06 15:48
We've spent the last few weeks talking about disassembling executables and how to read the result. Today, I want to wrap up that discussion with a look at a powerful third-party disassembly tool called Hopper.
Friday Q&A 2011-12-30: Disassembling the Assembly, Part 3: ARM edition at 2011-12-30 21:44
Gwynne finishes off her series on analyzing assembly code with a look at ARM assembly, for all of your iOS needs. Gwynne will be contributing the occasional article in the future as well as a guest author, without my introductions. Watch the Author field at the top of the post to see who's writing what. Without further ado, let's take a look at ARM.
Friday Q&A 2011-12-23: Disassembling the Assembly, Part 2 at 2011-12-23 20:48
Today I have the pleasure to present the followup to last week's guest post. Gwynne Raskind returns to complete her in-depth analysis of the assembly code generated by a small sample program.
Friday Q&A 2011-12-16: Disassembling the Assembly, Part 1 at 2011-12-16 15:02
As a small change of pace, today's post is written by guest author Gwynne Raskind. My last post touched a bit on disassembling object files, and Gwynne wanted to dive deeply into just how to read the output in detail. Without further ado, I present her wonderful in-depth look at reading
Friday Q&A 2011-12-02: Object File Inspection Tools at 2011-12-02 14:45
Being able to see all stages of your work can be immensely helpful when debugging a problem. Although you can get a lot done only looking at the source code and the app's behavior, some problems benefit immensely from being able to inspect the preprocessed source code, the assembly output from the compiler, or the final binary. It can also be handy to inspect other people's binaries. Today, I want to talk about various tools you can use to inspect binaries, both your own and other people's, a topic suggested by Carlton Gibson.
Friday Q&A 2011-11-11: Building a Memoizing Block Proxy at 2011-11-11 16:06
Last time, I talked about my crazy hack that misuses the Objective-C message forwarding machinery to do block proxying. This allows writing code that interposes in front of an arbitrary block to intercept its arguments, manipulate its return value, etc. Today, I want to present an exanmple of using this hack which almost verges on the practical. Specifically, I'm going to discuss how to use it to build a generalized block memoization facility.
Friday Q&A 2011-10-28: Generic Block Proxying at 2011-10-28 13:57
Here at Friday Q&A, I pride myself on occasionally taking my readers to places where normal people dare not tread. Today is one of those days. This is not a reader suggested topic, but today I want to talk about a fun hack I came up with that allows proxying block invocations in much the way that one can proxy Objective-C messages.
Friday Q&A 2011-09-30: Automatic Reference Counting at 2011-09-30 15:02
Since the moment Apple announced it, readers have asked me to write about Automatic Reference Counting, or ARC. Today is the day. I'll talk about Apple's new memory management system, how it works, and how to get the most out of it.
Friday Q&A 2011-08-19: Namespaced Constants and Functions at 2011-08-19 14:40
The inevitable rotation of the Earth means that it's once again time for another Friday Q&A. For today's edition, Jose Vazquez suggested that I discuss namespaced constants and functions in C.
Friday Q&A 2011-08-05: Method Signature Mismatches at 2011-08-05 14:45
You're happily writing code one day, click Build, and suddenly the dreaded warning appears:
warning: no '-fooMessage' method found (Messages without a matching method signature will be assumed to return 'id' and accept '...' as arguments.)You double-check your code and your method name is correct, so you shrug and move on. A few hours later, your program starts misbehaving strangely. What's going on? Today, I'll explore the mysterious world of Objective-C method signature mismatches, a topic suggested by an anonymous reader.
Friday Q&A 2011-06-03: Objective-C Blocks vs. C++0x Lambdas: Fight! at 2011-06-03 15:11
Blocks are perhaps the most significant new language feature introduced by Apple in years, and I've written a lot about them before. The new C++ standard, C++0x, introduces lambdas, a similar feature. Today, I want to discuss the two features and how they are alike and how they differ, a topic suggested by David Dunham.
Friday Q&A 2011-04-15: Compile-Time Tips and Tricks at 2011-04-15 16:20
Greetings, salutations, and welcome to another edition of Friday Q&A, the Fridayest source of information on the internet. This week, friend of the blog Jose Vazquez had the idea of discussing miscellaneous compile-time tips and tricks in C/Objective-C, like useful preprocessor techniques and compile-time asserts.
Friday Q&A 2010-12-17: Custom Object Allocators in Objective-C at 2010-12-17 18:27
Merry holidays, happy winter, and a joyous Friday Q&A to you all. Camille Troillard suggested that I discuss how to create custom object memory allocators in Objective-C, and today I'm going to walk through how to accomplish this and why you might want to.
Friday Q&A 2010-12-03: Accessors, Memory Management, and Thread Safety at 2010-12-03 16:53
It's once again time for a brand new edition of Friday Q&A. This week, I'm going to talk about accessors, and how to properly deal with memory management and thread safety when creating them, a topic suggested by Daniel Jalkut.
Friday Q&A 2010-11-19: Creating Classes at Runtime for Fun and Profit at 2010-11-19 17:53
It's time for another edition of Friday Q&A. In the last Friday Q&A, I discussed how to create classes at runtime in Objective-C. Today, I'm going to discuss how to actually make practical use of this technique.
Friday Q&A 2010-11-6: Creating Classes at Runtime in Objective-C at 2010-11-05 17:08
Friday Q&A is back! I had some very important slacking to take care of for the past couple of months, but now I'm ready to resume business as usual. For this return to Friday Q&A, I'm going to talk about how to create Objective-C classes at runtime, a topic suggested by Kevin Avila. This topic is meaty enough that this will be a two-parter; today's post will talk about the basics of how to create classes at runtime, and then the next one will discuss uses for such classes and how to take advantage of them.
Friday Q&A 2010-08-27: Defensive Programming in Cocoa at 2010-08-27 15:19
Welcome back to another word-laden edition of Friday Q&A. About a year ago, I wrote a post on defensive programming. That post covered defensive programming in a general sense, and Scott Gould has requested that I write one specific to various standard Cocoa practices, which is what I will be talking about today.
Friday Q&A 2010-08-12: Implementing NSCoding at 2010-08-13 16:35
Welcome back to another frightening edition of Friday Q&A. This time around, friend and local OS X coder Jose Vazquez has suggested that I discuss how to implement
NSCodingin Objective-C classes.
Introducing MAZeroingWeakRef at 2010-07-16 20:19
I'm extremely excited to announce a new library for Cocoa and Cocoa Touch development:
MAZeroingWeakRef. In short, it's a library which allows zeroing weak references to be used in retain/release Cocoa code. This has all sorts of uses and should make retain/release coding less painful. While I discussed this in detail in my Friday Q&A post this week, I also want to make a separate announcement for people who don't want to read through all of the horrible details.
Friday Q&A 2010-07-16: Zeroing Weak References in Objective-C at 2010-07-16 20:18
It's that time of the biweek again. For this week's Friday Q&A, Mike Shields has suggested that I talk about weak references in Objective-C, and specifically zeroing weak references. I've gone a bit further and actually implemented a class that provides zeroing weak references in Objective-C using manual memory management.
Friday Q&A 2010-06-18: Implementing Equality and Hashing at 2010-06-18 14:48
Welcome back to a late edition of Friday Q&A. WWDC pushed the schedule back one week, but it's finally time for another one. This week, I'm going to discuss the implementation of equality and hashing in Cocoa, a topic suggested by Steven Degutis.
Friday Q&A 2010-04-16: Implementing Fast Enumeration at 2010-04-16 16:35
Last week I discussed the various options available in Objective-C for enumerating over a collection This week I'm going to finish up the discussion of enumeration with a guide on how to implement Fast Enumeration in your own program.
An Objective-C Continuations Library at 2010-04-13 16:25
A couple of months ago I wrote about using Continuation Passing Style in Objective-C as an alternative technique for returning errors from methods. The major downside to that technique is that it integrates poorly with Cocoa, since Cocoa isn't written to use CPS. Jordan Breeding has spent the intervening time building up an impressive CPS adapter library which allows converting any Cocoa
NSError **call into CPS style with virtually no work. Source code and extensive examples are available, and I encourage you to check it out.
Friday Q&A 2010-04-09: Comparison of Objective-C Enumeration Techniques at 2010-04-09 11:17
Welcome back to another edition of Friday Q&A. Preston Sumner has suggested that I talk about different ways of enumerating over collections in Cocoa, and how to implement Fast Enumeration. This will be a two part series: this week I will look at the different enumeration techniques and their pros and cons, and then next week I will take you through implementing Fast Enumeration on a custom object.
Friday Q&A 2010-02-05: Error Returns with Continuation Passing Style at 2010-02-05 18:36
The Earth has moved 6.9 degrees around the Sun since my last post, which means it's time for another edition of Friday Q&A. This 6.9-degree segment, Guy English has suggested that I talk about the use of continuation passing style to simplify error returns in Objective-C code.
Friday Q&A 2010-01-29: Method Replacement for Fun and Profit at 2010-01-29 19:00
It's that time of the week again. For this week's Friday Q&A Mike Shields has suggested that I talk about method replacement and method swizzling in Objective-C.
Friday Q&A 2009-11-27: Using Accessors in Init and Dealloc at 2009-11-27 16:32
It's Black Friday, and that means it's time for another Friday Q&A. Today I'm going to talk about the use of accessors in Objective-C init/dealloc methods, a topic suggested by Jon Trainer.
Friday Q&A 2009-11-20: Probing Cocoa With PyObjC at 2009-11-21 02:44
It's another Friday and time for another Friday Q&A. This week, fellow Amoeba Jeff Johnson suggested talking about using Cocoa from the command line using Python and PyObjC.
Friday Q&A 2009-10-02: Care and Feeding of Singletons at 2009-10-02 15:59
It's time for another Friday Q&A. I hope everyone who had a chance to go to C4 had a good time and is back home safe and sound. This week I'm going to discuss singletons, both how to make them and when to use them, as suggested by Jon Trainer.
Friday Q&A 2009-05-22: Objective-C Class Loading and Initialization at 2009-05-23 00:37
Welcome back to another cromulent Friday Q&A. After taking a few weeks off I intend to resume the regular schedule. We'll see how far that intention takes me, but I'm hopeful. This week I'm going to take Daniel Jalkut's suggestion to discuss class loading and initialization in Objective-C.
Friday Q&A 2009-03-27: Objective-C Message Forwarding at 2009-03-27 16:50
Welcome back to another exciting Friday Q&A. This week I'm going to continue the series on the Objective-C runtime. Yuji Tachikawa suggested talking about how
@dynamicproperties work in CoreData and I'm going to take that and expand it to talk about message forwarding in general.
Friday Q&A 2009-03-20: Objective-C Messaging at 2009-03-21 01:59
Welcome back to another Friday Q&A. This week I'd like to take Joshua Pennington's idea and elaborate on a particular facet last week's topic of the Objective-C runtime, namely messaging. How does messaging work, and what exactly does it do? Read on!
Friday Q&A 2009-03-13: Intro to the Objective-C Runtime at 2009-03-13 14:13
Welcome back to another Friday Q&A, on another Friday the 13th. This week I'm going to take Oliver Mooney's suggestion and talk about the Objective-C runtime, how it works, and what it can do for you.
The How and Why of Cocoa Initializers at 2008-10-09 23:43
One of the longest ongoing controversies in the Cocoa community is how to write your init methods. More specifically, how to properly call your superclass's initializer. In the hopes of putting this controversy to rest, I want to walk through the right way to write an initializer and exactly why this is the right way.
Performance Comparisons of Common Operations, iPhone Edition at 2008-03-19 21:40
I finally got a chance to run my performance comparison code on an iPhone, so we can see just how much horsepower this little device has. I still am not able to load my own code onto the device myself, so I want to thank an anonymous benefactor for adapting my code to the new environment and gathering the results for me.
Performance Comparisons of Common Operations, Leopard Edition at 2008-01-12 21:01
By popular demand, I have re-run my Performance Comparisons of Common Operations on the same hardware but running Leopard.
Leopard: First Impressions at 2007-11-30 23:12
Leopard's been out for a while now and brings with it a lot of interesting new tools for the Mac programmer. I've had the chance to work with some of them and want to offer my opinion on how they've worked out.
Performance Comparisons of Common Operations at 2007-08-25 00:00
We all know that premature optimization is the root of all evil. But a recent conversation brought to mind that we often don't really know the runtime costs of the code we write. While we should be writing foremost for correctness and clarity, having an idea of these speeds is good, especially when we get it into our heads that some operation is much more costly than it really is. With that in mind, I compiled a list of common Cocoa operations and how much time they require at runtime.
More Fun With Autorelease at 2007-02-08 00:00
I just hit a subtle but commonly known bug for the first time. I thought I'd share my fun with the world. Everybody reading this blog should know about autorelease pools and how they work in Cocoa. As everybody knows, every time you go through the event loop, Cocoa blows away the old pool and makes a new one for you, so that all of your autoreleased objects go away and your new ones go into a fresh pool. That way you never build up more objects than get produced during a single event loop cycle.
Using Evil for Good at 2006-07-14 00:00
People who know me as a programmer probably know that I am a great hater of C++. As someone who does a lot of Cocoa, this extends naturally into hating Objective-C++. But I made good use of Objective-C++ in ChemicalBurn and I thought I'd share.
Autorelease is Fast at 2006-06-07 00:00
If you've done much Cocoa programming, you've probably run into a situation where you needed to create a local autorelease pool because of some sort of loop. And you've probably run into advice telling you not to create and destroy the pool for every iteration, because that would be slow. I never believed that it could be significant, and I finally took the time to test it today. What's the verdict? Just as I thought, making autorelease pools is really fast.