Monday, August 27, 2012

Forward Iterators


Introduction
Objective-C and the libraries in the Cocoa framework provide us with iterators, however they are to be used traversing class containers (NSArray, NSSet, etc). When we need to use iterators to traverse a raw memory container of structs, pointers, or primitive types, then we don’t have any pre-built solution and most often have to use a custom implementation.
In this article we will see a simple way of using iterators to traverse a raw memory container of pretty much anything, without departing from the familiarity of Objective-C code. We will use a simple class derived from NSObject and delegation to implement a forward iterator.
Forward Iterator
Our sample code is very simple to understand, nevertheless once the concept is understood, it can be easily expanded to more complex scenarios. In our case we chose to create a structure to store time (hours, minutes, and seconds), and we allocated enough memory, using malloc, to fit 100 entries of such structure.
typedef struct {
    int seconds;
    int minutes;
    int hours;
} TimeStruct;

The iterator we implemented is a forward iterator. It starts iterating from the first element (element zero) in the raw memory space, and moves forward sequentially to the last one. It cannot be rewinded, thus it is only good to be used one time. After the memory space has been traversed by the forward iterator, the iterator should be discarded.
In its implementation our forward iterator declares a delegate protocol and requires 3 methods to be implemented by the delegated class. Those methods should return:
  • The number entries in the allocated memory.
  • A pointer to the allocated memory.
  • The size of an element within the allocated memory.
The implementation of our forward iterator and sample code can be found at GitHub. Clone and use it freely at:
$ git clone git@github.com:dcirne/ForwadIterator.git
We will be using modern Objective-C with ARC and automatic synthesis of properties in our code. Open main.m and see that all it does is to create an instance of DCSampleCode and traverses forward the memory container. DCSampleCode declared the struct above, populates its 100 entries, and implements the delegate methods of the DCIterator class. The iterator is implemented in the DCIterator class and uses familiar nomenclature for its methods, such as hasNext and next.
for (; [iterator hasNext];) {
    t = [iterator next];
    printf("%d - %02i:%02i:%02i\n", index++, t->hours, t->minutes, 
           t->seconds);
}

As you could see, our example is quite simple to understand, and you now can use this forward iterator with more sophisticated cases.


Wednesday, March 9, 2011

ESPN's Game Ball - Jan/2011

ESPN has a special and unique way of recognizing and rewarding the employees who have done an outstanding job. The Game Ball is a distinct token that I was honored to receive on Jan/2011.

Tuesday, April 20, 2010

Multithreading: An Extensive Study on Linux, OpenSolaris, and Windows

There are many reasons why one may choose a particular operating system to run on their computer: availability of software, technical skills, etc. Among those reasons one may choose the operating system with the best performance, or the one with the lowest cost per transaction. This paper examines three operating systems (Linux, OpenSolaris, and Windows) and their respective capabilities of taking advantage of the multiple cores present in modern processors by executing operations with integers, floating points and math, and I/O in a multithreaded way, achieving parallelism in the execution of those operations, and then tries to reason the measurements from the experiments in the economics of an operating system.

Download the complete paper here

Friday, January 1, 2010

ScoreCenter TV Commercial



This is ScoreCenter. A commercial produced by ESPN to promote its flagship product for the iPhone and #1 sports app in the App Store.

Tuesday, November 17, 2009

Mobile Marketing Award

In the second half of 2009 ESPN's ScoreCenter won an award for innovation. It was nice to have the opportunity to be there an bring a new piece of hardware home.

Oke Okaro, Dalmo Cirne, and Brian Doyle.



Friday, September 21, 2007

Convergence of Information: How Corporations Can Dramatically Enhance the Decision-Making Process.

A company has to understand and measure its processes in order to properly manage the business. This is not an easy task, since the information is spread among various systems in an heterogeneous computational environment. Convergence of Information deals with the challenge of providing a single entry point where all key metric elements can be accessed, giving agility to management and executives, and enhancing the overall performance of the corporation.

Download paper here.

Friday, May 11, 2007

A Different Approach to a Window System: The Modeling and Applications of a Non-Overlapping Window Environment.

The era of Web 2.0 allowed us to implement and use windows inside a web browser, without impact neither on performance nor usability. The possibility of desktop-like experience while using web applications, broads the horizon of programs that can benefit from all the advantages that come with the Internet.

In this paper we are going to explore a different approach to how a dynamic window system can function and behave. Windows squeeze and expand, resembling an accordion. This way, windows give a little space to other windows (when required) , or request a larger area, within the canvas, to allow the user to concentrate his/hers focus, without loosing the sight of what is in the other windows.

Download the complete paper here.

A flash binary executable demo can be downloaded here.

The complete source code (written in OpenLaszlo) can be downloaded here.