How to create a RAM disk

I just posted to this lisppaste with a punt solution. Since this solution really has nothing to do directly with the problem stated, I thought I'd share it with you as well, with HTMLization and some editing from the original.

  1. hdid -nomount ram://num_sectors (sector = 512 bytes = 0.5 K)

    This outputs a device path (/dev/foo) on stdout.

  2. newfs_hfs -v volume_name device_path

    Formats the RAM disk as HFS+. See the manpage for other options.

  3. diskutil mount device_path

    The RAM disk will be mounted at /Volumes/volume_name.

You could also do something involving mount(8) instead of diskutil if you wanted to mount it inside NSTemporaryDirectory(). Remember to unmount it (hdiutil detach device_path, or the Eject command in the Finder or Dock) when you're done.

Technorati tags: .


Post a Comment

links to this post:

Create a Link

<< Home