Entries Tagged 'Computer Science' ↓

Create a unique identifier (UUID) in objective-c

I’m working on an iPad project for a client and found myself needing to generate a unique identifier. I found some code from Erica Sudan here. Works like a charm.

  1. + (NSString *)uuid {
  2.     CFUUIDRef theUUID = CFUUIDCreate(NULL);
  3.     NSString *uuidString = (__bridge_transfer NSString *) CFUUIDCreateString(NULL, theUUID);
  4.     CFRelease(theUUID);
  5.     return uuidString;
  6. }

Note that this code is for when using ARC. If you’re not using ARC, you’ll need to autorelease the string:

  1. + (NSString *)makeUUID {
  2.     CFUUIDRef theUUID = CFUUIDCreate(NULL);
  3.     NSString *uuidString = [(NSString *) CFUUIDCreateString(NULL, theUUID) autorelease];
  4.     CFRelease(theUUID);
  5.     return uuidString;
  6. }

The Yin to the Yang

Some reading I was doing for a graduate course I’m taking got me to thinking about the evolution of electronic commerce. I remember all the hype around it in the late ’90s. “Brick and mortar is dead.” That sort of thing. Oracle had an ad that said something like “The Internet. This changes everything.” Certainly it was over hyped. But there’s no denying that the Internet has indeed had a significant impact on the world. For example, the globalization of the white collar workforce is what I consider to be one of the most significant changes brought about by the Internet.

What wasn’t discussed nearly enough at the time, and probably still isn’t today, is all of the other changes and innovations that come along with the good stuff (such as shopping on amazon.com). The Yin to the Yang, if you will. Part of the “everything” the Internet has changed has to do with crime, privacy, psychological afflictions, and more. SPAM, phishing, identity theft, cyber warfare, cyber terrorism… Those are some of the obvious downsides. I’m also sensitive to some of the more subtle issues. For example, hardcore iPhone and Blackberry users often have a constant assault of emails and instant messages which may result in the shortening of their attention spans and a severe negative impact on productivity – whether personal or at work. Here’s another subtle issue: bad information. Just because it’s published on the Web doesn’t mean it’s accurate. Wikipedia is a well-known example of this issue.

Anyway, just thinking out loud…

Segmentation and Paging in the Intel IA-32 Processors

Note: I wrote this as a forum post for one of my graduate courses. I’m sharing it here just in case anyone else finds it interesting. –Ron

16-bit Processors and Segmentation (1978)

The IA-32 architecture family was preceded by 16-bit processors, the 8086 and 8088. The 8086 has 16-bit registers and a 16-bit external data bus, with 20-bit addressing giving a 1-MByte address space. The 8088 is similar to the 8086 except it has an 8-bit external data bus.

The 8086/8088 introduced segmentation to the IA-32 architecture. With segmentation, a 16-bit segment register contains a pointer to a memory segment of up to 64 KBytes. Using four segment registers at a time, 8086/8088 processors are able to address up to 256 KBytes without switching between segments. The 20-bit addresses that can be formed using a segment register and an additional 16-bit pointer provide a total address range of 1 MByte.

The Intel 286 Processor (1982)

The Intel 286 processor introduced protected mode operation into the IA-32 architecture. Protected mode uses the segment register content as selectors or pointers into descriptor tables. Descriptors provide 24-bit base addresses with a physical memory size of up to 16 MBytes, support for virtual memory management on a segment swapping basis, and a number of protection mechanisms.

The Intel 386 Processor (1985)

The Intel 386 processor has a 32-bit address bus that supports up to 4-GBytes of physical memory. It has a segmented-memory model and a flat memory model. The 386 introduced paging, with a fixed 4-KByte page size, providing a method for virtual memory management.

The Intel Pentium Processor (1993)

The pentium added extensions to make the virtual-8086 mode more efficient and allow for 4-MByte as well as 4-KByte pages. This feature is known as Page Size Extension (PSE). The PSE allows for page sizes of 4 MB to exist along with 4KB pages.

The motivation for the larger page size
Assume that a task will be accessing a large buffer in memory and that it is the OS’s intention that the processor should follow the same rules of conduct when accessing any location(s) in this buffer. As an example, assume it is a 2MB video frame buffer in memory. Using 386-compatible paging, the OS would have to set up 512 PTE’s, each one associated with a 4KB page within the buffer and each one with identical attribute bit settings (i.e., the attribute bits that define the processor rules of conduct within the page). Setting up and maintaining 512 PTEs is a lot of housekeeping.

Sources

Intel (2009). Intel® 64 and IA-32 Architectures Software Developer’s Manual Volume 1: Basic Architecture

Shanley, Tom, & Colwell, Bob (2004). The Unabridged Pentium 4 IA32 Processor Genealogy. Addison-Wesley Professional