Archive for February, 2010

A subtlety of object identity in Obj-C


2010
02.26

A problem: given an object a of class A that aggregates a publicly accessible instance of class B determine if an instance changed by polling periodically. This comes up often in concurrent systems where an object change warrants a response while KVO is undesirable. The first thought that comes to mind is to a cache the instance of B during each cycle of polling after the comparison of the cached instance to the present value.

Our code might look like this

if (cachedB != [a valueOfB]) { triggerEvent(...); }
cachedB = [a valueOfB];

Unfortunately this fails miserable due to the fact that a newly allocated instance of B may occupy the same memory location as the previous one (assuming, of course, that we never retain the cached value). This is a low probability failure and is extremely hard to debug. This bug is solved by storing a timestamp upon change of instance of B inside a, and cacheing it instead of the memory address.

Joy


2010
02.24

Authentic joy is everlasting
A thing that freely permeates
As born in hearts of lovers lusting
So nascent is when we create

It hides itself in child’s smile
In ray-ing clouds of sunrise
It so resides in every shining
Of every memorable time

@rpath


2010
02.09

Leopard and (Sno) have a new way of specifying deployment location of a dynamic lib. Follow this link for an in depth explanation.

Command line is your friend :)


2010
02.09

A nifty command  python -m SimpleHTTPServer will start serving the current directory on port 8000. Seems like a cute alternative to broken iChat transfers… found it here among other cute Linux miscellanea.

When in doubt about missing symbols during linking nm <filename> can be an invaluable asset. When struggling with questions about architectures of a binary otool -vf <filename> is the there to help.