wannabegeek

Icon

Things I find interesting – generally programming

Compare C++ locking mechanisms for performance

As multithreaded applications become more and more common (mainly due to the increase in number of available CPU cores on modern computers), inter-thread communication get a much higher focus when developing applications. As the compiler writers are gradually implementing all the C++11 features, we can begin to take advantage of them, such as atomic variables, and the inbuilt threading (std::thread) and locking mechanisms (std::mutex etc.).

In this post I’m going to compare some locking mechanisms for performance (mutex locking, spin lock and no locking).
Read the rest of this entry »

C++ Worker Threads for Application Concurrency

The changes made C++11 has opened up many opportunities for simplifying application concurrency, especially with the new platform independent std::thread (ok, we have had boost::thread for some time). Here i’m giving an simple example of creating a dispatch pool for so separate units of work can be processed concurrently.

This uses quite a few C++11 features so, you’ll need to be using gcc 4.7.2, clang 4.1 or later.

The aim of this post is to create a dispatch pool which can take a std::function<> and processes it concurrently e.g.

TFWorkerDispatch dispatch;
for (int p = 0; p < 20; p++) {
	dispatch.queueTask([=]() {
		//
		// Some complex task
		//
	});
}

Read the rest of this entry »

Performance analysis on OSX and iOS

Within Xcode there are a few tools for measuring performance of you applications, the main on is Instruments, this is great for determining the amount of time spent in a particular method to work out where your bottlenecks are.
Often I test a few versions of my code implemented in different ways, the main thing you want to know is “Which is faster?”.
Read the rest of this entry »

C++ Ring Buffer Implementation

Ring buffers are becoming increasingly popular in low latency systems, this is mainly because it is possible to implement it in a lockless way i.e. you can have different producer and consumer threads, but there is no thread locking required.
Read the rest of this entry »

Fixing NSLayoutContraints on a Custom UITableViewCell in Edit Mode

The appears to be an issue in iOS6 when using auto layout within a custom UITableViewCell. Generally the cells are layed out correctly until you enter edit mode. In edit mode the contents of the cell should be shifted to allow space for the delete button or selection indicator, but with auto layout this is not the case.

Incorrect Layout

Incorrect Layout

Correct Layout

Correct Layout

Read the rest of this entry »

Hiding UITabBar and presenting a UIToolBar in edit mode

I one of my projects I wanted to replicate the behaviour of the UITabbar found in the iOS Photos app. When you tap on the edit button in the “tile view”, the UITabBar disappears and a UIToolbar with delete and move options appears in it’s place.
Non-editing modeEditing mode

Read the rest of this entry »

NSSplitView Problems with autolayout

In Mac OS X 10.7 (Lion) Apple introduced autolayout (See here for more information).
However, NSSplitView seems to cause some issues when using constraints. Creating manually in code is probably OK, but using Interface Builder is far easier for complex projects.

Read the rest of this entry »

TFDatePicker a User Friendly Date Picker for OS X

Here i have implemented a custom subclass of NSDatePicker, which presents a popover view allowing the selection of the date from a calendar view.

Read the rest of this entry »

UIManagedDocument and background updating

I think I have come across a serious limitation of UIManagedDocument when updating as a background task.
I have been attempting to write an application which records GPS coordinate information, storing this data in a CoreData backed UIManagedDocument. For this to work, as with many GPS recording applications, I really need this to continue storing data as a background task (i.e. while the user is using a different application).

When running in the background everything appears to be good, I’m receiving location updates and creating NSManagedObject’s and the appropriate relationships. However, when the application returns to the foreground, all the managed objects are faulted.
Read the rest of this entry »

User Defined Runtime Attributes


“User Defined Runtime Attributes” are variables which can be set using key-value paths via Interface Builder. These properties work for Mac OS X 10.6 and in iOS 5.0 and later.
I have often overlooked this functionality, but actually they can be extremely useful, and prevent subclassing or writing extra code to alter properties of a class.

You will find the “User Defined Runtime Attributes” in the “Identity Inspector”‘panel in interface builder. Here you can set various attributes using key-value paths of the class your re-implementing.
Read the rest of this entry »