views:

259

answers:

3

For my understanding there are always two types of memory:

  • the working storage

  • the "disk space"

So when you have a 16 GB iPhone, does it have 16 GB of working storage? or 16 GB of "disk space"? Which "Memory" is Apple talking about in his Docs, when it comes to performance and memory management? It looks like the working storage, but I am not sure. Actually I thought the iPhone is a huge brick of working storage, since all that stuff is just a solid block of chip memory (no hard drive).

+8  A: 

The iPhone has 16GB (or 8 or 4, depending on the model) of non-volatile flash memory that persists even when the power is turned off. It also has 128MB of volatile DRAM that gets lost when the power is turned off. The relative differences are:

  • Flash memory is cheap, DRAM is expensive
  • Flash memory is slow, DRAM is fast
  • Flash memory is non-volatile, DRAM is volatile

The flash memory is essentially like a hard drive, except it's a solid-state memory, not a rotating platter of magnetic dipoles.

Generally, in iPhone development, when you're talking about memory, you're talking about DRAM. DRAM is a more limited resource and more likely to run out, since it's very easy for an app do eat up megabytes by poor memory management. It's a lot harder to run out of flash memory, since doing so would involve writing very large files into the file system.

Adam Rosenfield
+2  A: 

A simpler way of explaining it:

Every iPhone has 128 MB of RAM. Your application generally can't use more than ~22 MB of it, and it does not use a swapfile for RAM expansion.

The advertised storage capacities (4/8/16 GB) are "disk" space for the filesystem.

Marco
+1  A: 

The flash memory that makes up most of the iPhone's advertized "memory" is a kind of hybrid between RAM and "disk space" in its most important characteristics:

  • Less expensive than RAM, more expensive than a harddisk
  • Sequential transfer rate is lower than RAM's, about the same as a harddisk's (though this really depends on the type and quality of flash memory)
  • Random access delay is higher than RAM's, but much lower than a harddisk's

The last point is the most important one from a programmer's point of view. All kinds of basic programming techniques and an incredible amount of effort hinges on the fact that compared to most other things that happen in a computer, random access to harddisk memory takes eons because it involves physical movements - and that's where most of your storage is.

This basically means that in an environment with flash memory instead of a harddisk, you can get away with a lot of shit that would absolutely kill an app operating with a harddisk. There aren't really any downsides except for the limited amount of storage. Of course, conversely, it may mean that an app ported from the iPhone to a PC may exhibit godawful performance. Then again, the PC's OS might hide this by caching HD accesses in the more plentiful RAM.

Michael Borgwardt