Blocks, Episode 2: Life Cycles

Blocks are quite special constructs. The chief reason for this is the way that they are able to capture the lexical scope in which they were defined, keeping the values of variables defined on the stack preserved with them. While this is very powerful, it leads to some questions of memory management, and therefore some new rules to learn. To begin with, we’ll look at a block’s life-cycle.

Blocks, Episode 1

I was expecting to have to wait until the release of Snow Leopard to write any of this small series of tutorials on using Blocks and the different paradigms you might want to learn as a result. I will still have to do so to really get involved with the actual capabilities of things like Grand Central Dispatch. However, since Landon Fuller / Plausible Labs released their port of the Blocks runtime to OS X 10.5 and iPhone OS 3.0, I can give you a heads-up on the things you can do with them, and on the new programming behaviours they allow you to implement.

AQGlassButton Internals

The AQGlassButton class is implemented using two CoreGraphics objects: a CGMutablePathRef and a CGGradientRef. The gradient defines the actual gloss appearance, while the path defines the shape of the button, and is used for both drawing its outline and for clipping the gradient when that is rendered.

AQGlassButton on GitHub

This is a simple glass-effect UIButton subclass, implemented entirely using CoreGraphics. It’s probably not up to the sort of fidelity you can get with a stretched image (and a good illustrator), but it should serve for a nice introduction to the relevant techniques: paths, gradients, and colors.

Lockless lazily-initialized static/global variables

So we all know (or we should) about the potential perils of double-checked locking. These can be mostly mitigated by judicious use of the volatile keyword, at least in languages which support it, but in this wonderful world of multi-core and multi-processor development, there are still some problems[PDF] to be aware of (there’s optimizing-compiler theory in there; if that scares you, just take my word that it’s got problems).

symbolicatecrash can kiss my arse

So I just spent all this evening debugging the fixed version of symbolicatecrash, attempting to see why it wasn’t working for me. I found a few bugs, fixed them (eventually—Perl is a language I’ve not used extensively, and not at all for about 10 years). Here I’ll go through what I had to change & why.


© 2009-2019. All rights reserved.

Powered by Hydejack v8.5.2