Less Wrong #2

  • 5 sec usability test. Show a page or screen to a user for five seconds and take it off. Ask them what they thought of it. Reveals a lot about what you’re getting right, and what is wrong.
  • Creation of cocoa objects –
    1. Two stage creation vs one stage creation of cocoa objects.
    2. In two stage creation, allocWithZone.
    One stage creation = allocation of memory + initialization of all the class variables are done with one method. But the problem with doing it this way is that memory alloc can come from mulitple sources. Plain RAM, shared memory between processes, memory card etc. And inits can usually take multiple overloads.
    So a combination of both = m*n methods that need to be written for each class where m = # of memory sources a class can accept and #n = number of inits a class can accept.

    Two stage creation – Cocoa just uses two-stage creation to avoid the complications mentioned above. NSObject, superclass of all the objects in Cocoa implements two methods – alloc: and allocWithZone:. Most classes use these methods to allocate memory. A call to this, returns memory that can hold the object + a pointer to the object (isa *) at the top of the memory that has been allocated that points to the object that actually requested for the creation of this memory.

    Zones in cocoa are blocks of memory that are allocated next to each other in RAM. So whole zones can be paged out or paged in by the OS. If, however, there is no concept of zones and the objects are placed randomly in memory, one object can be paged out while a dependent object is still in the memory. There’s a high chance of the object in memory calling the object that swapped out. And if the other object in memory is swapped out meanwhile, it can lead to thrashing. So, all memory requested by the program is allocated to a zone which resides in memory blocks next to each other.

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