Objective C: CFQueueDestroyer

CFQueueDestroyer is a simple ObjectiveC class used to defer deletion of objects until a later date. Colloquially you can consider it be a “bucket” to discard no longer required objects into.

This could be worked into an object pooling or batch procedure invoker with relatively minimal work.

In practice, I use this within a Cocos2D game (link) I’m developing that harnesses the awesomeness of Box2D. When you’re mid physics tick you don’t want to be destroying Box2D bodies, so you defer the deletion of them until just after the tick. The role of the classes here are to act as a container for them with a singleton implemented around it too.

Also, before I get flamed, strictly speaking it’s not a queue – oddly enough ObjectiveC doesn’t have a queue implementation is the NS classes (Typically people utilise an NSMutableArray). However, I am logically “queueing them up for deletion” in the pattern sense.

Further, for the CFPhysicsBodyQueueDestroyer example you’ll notice a static createWithWorld:(b2World*)world function is implemented. Strictly speaking a singleton shouldn’t have parameters fed into it’s creation like this, but sometimes in games development you end up having to be a bit flexible with design patterns 🙂 </excuse>

Where can I get it?

You can find it on Github here

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s