tag:blogger.com,1999:blog-75925021022390711692024-03-13T00:16:18.134-06:00Bits about BytesMusings about computer stuff that some of my non-geek family and friends don't want to wade through on my "regular" blog.Alexhttp://www.blogger.com/profile/13385489484617545171noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-7592502102239071169.post-8363368827836091492010-04-30T17:14:00.002-06:002010-04-30T17:28:48.926-06:00Downgrading packages in Arch LinuxOn occasion (actually today was the first time) there is need to downgrade a package in Arch Linux. Yesterday I did a `pacman -Syu`, which upgraded gcc from 4.4.3 to 4.5.0. Today, I learned that 4.5.0 is unable to compile Moab. You'd think that a new release of your trusty compiler would work at least as good as the last one, but that's a topic (spelled R-A-N-T) for another day. When this catastrophe strikes, you can do the following to recover.<div><br /></div><div>1. On my Arch system, package files are kept in /var/cache/pacman/pkg. Go there.</div><div><br /></div><div>2. Find the desired package. In this particular case, /var/log/pacman.log told me that yesterday I upgraded from 4.4.3-2 to 4.5.0-1. So my working compiler up until yesterday was gcc 4.4.3.</div><div><br /></div><div>3. "Upgrade" to the desired package: `pacman -U gcc-4.4.3-2-x86_64.pkg.tar.xz` and `pacman -U gcc-libs-4.4.3-2-x86_64.pkg.tar.xz`</div><div><br /></div><div>4. Also in my case I'll want to stick with gcc 4.4.3 for a while now, so you can modify the IgnorePkg line in /etc/pacman.conf as follows:</div><div><br /></div><div>IgnorePkg = gcc gcc-libs</div><div><br /></div><div>This causes pacman to skip over gcc and gcc-libs when you do a system-wide upgrade (mine prints a warning to say it's being ignored, which I don't consider to be a bad thing).</div>Alexhttp://www.blogger.com/profile/13385489484617545171noreply@blogger.com1tag:blogger.com,1999:blog-7592502102239071169.post-45576117920466002982010-04-08T14:46:00.002-06:002010-04-08T15:01:36.470-06:00Terminal colors, all-day readability, and Arch LinuxA recent system upgrade broke my terminal colors. I don't know what exactly it was, or how it happened, but I opened a new terminal window, did a `ls`, and all my directories were bold and blue again. I personally find this difficult to read as I use a very dark blue background in my terminals (something on the order of #111133).<br /><br />The solution:<br /><br />Run the following command to create a default dir_colors file (the file that generates the colors for the ls command):<pre> `dircolors -p > ~/.dir_colors`<br /></pre>Then, add the following to your .bashrc file:<span class="Apple-style-span" style=" white-space: pre; font-family:monospace;font-size:13px;"> </span><div><pre> # set the TERM variable to a color-enabled type (xterm-color)<br /> export TERM="xterm-color"<br /><br /> # source my own .dir_colors file<br /> if [ -f $HOME/.dir_colors ]<br /> then<br /> eval `dircolors -b $HOME/.dir_colors<br /> fi<br /></pre></div>This will allow you to customize what colors describe what objects for the ls command.<div><br /></div><div>I personally make the following changes in ~/.dir_colors:</div><div><pre>- DIR 01;34<br />+ DIR 00;36 # directories are cyan and non-bold<br /></pre></div>Then, I go through and turn off bold (swap 00 for 01) for almost everything. The only things I leave bold are executables and sym/hardlinks. For more info on dir_colors, see<div><pre> man dircolors<br /></pre>or<pre> man dir_colors</pre></div>Alexhttp://www.blogger.com/profile/13385489484617545171noreply@blogger.com0tag:blogger.com,1999:blog-7592502102239071169.post-50271944682223902422010-03-05T00:12:00.003-07:002010-03-07T17:02:21.987-07:00Backup Now, Please.I realize it's been over a year since my last post, and I have a bunch of stuff stacked up. But this was pretty slick and frankly, I don't want to lose it. So here goes.<div><br /></div><div>The problem: Oftentimes when I'm working on a project, being the hard-drive-paranoid-soul that I am, as I finish a milestone I'll run a Time Machine backup, and also sometimes rsync my project directory to Dropbox. However, it annoys me to shift to the mouse/trackpad to run the time-machine backup, then switch to the Terminal to run the rsync backup.</div><div><br /></div><div>The solution: A decidedly love-sided instance of my love-hate relationship with AppleScript</div><div style="color: #22ffaa; font-family: fixed-width;"><br /><pre>do shell script "/System/Library/CoreServices/backupd.bundle/Contents/Resources/backupd-helper >/dev/null 2>&1 &"<br /><br />property nullStr : ""<br />set defaultSrc to "/path/to/project/dir"<br />set defaultDest to "/path/to/destination/dir/in/Dropbox"<br /><br />--- cancel actions from either of these dialogs will effectively cancel the script<br />set dropBoxSource to text returned of (display dialog "Dropbox backup source?" default answer defaultSrc)<br />set dropBoxDest to text returned of (display dialog "Dropbox backup destination?" default answer defaultDest)<br /><br />if dropBoxSource is not equal to "" and dropBoxDest is not equal to "" then<br />set rsyncCmd to "rsync -rav " & dropBoxSource & " " & dropBoxDest<br />display dialog ("Run: '" & rsyncCmd & "'")<br />--- if the user cancels the dialog here, the rsync won't run. this is just what we want :)<br /><br />--- set a 2-hour timeout for the rsync command<br />with timeout of 7200 seconds<br /> do shell script rsyncCmd<br />end timeout<br />end if<br /></pre><br /></div><br /><div>I saved this applescript as an application, which I can then invoke via spotlight/Quicksilver/Alfred etc, thus removing the problem of hunting for the Time Machine menu.</div><br /><h1 style="color: #ff0000">DISCLAIMER:</h1>The shell script that runs the Time Machine backup is a non-documented, non-supported, run-at-your-own-risk solution. It works for me, but I'm making absolutely no guarantees that it won't break something. For that matter, you ought to know what rsync does before feeling too comfy with the rsync backup either.Alexhttp://www.blogger.com/profile/13385489484617545171noreply@blogger.com2tag:blogger.com,1999:blog-7592502102239071169.post-8657504421708854882009-01-27T08:10:00.003-07:002009-01-27T08:24:23.630-07:00Breaking long lines in VimVim allows you to set a line length at which to break long lines, which I use in text files to break at 80 characters. However, in source files, I don't want it to break lines right at 80 characters lest it break in the middle of something that doesn't want to be broken in.<br /><br />So I put the following in my .vimrc as a shortcut to breaking at 80 characters only when I want it to:<br /><br /><code><br />map \br 80\|? <cr>r<cr><br /></code><br /><br />This tells Vim to go to column 80, search backward for the previous " " (space), and replace it with a carriage return.<br /><br />I use this primarily for breaking comment lines at 80 characters. If Vim is set up properly (I can't remember the setting off the top of my head, but maybe I'll post it here later) the new line you inserted will be marked as a comment also (in the case of # or " comment markers, as this will obviously work with C/Java style multi-line comments).Alexhttp://www.blogger.com/profile/13385489484617545171noreply@blogger.com4tag:blogger.com,1999:blog-7592502102239071169.post-44961330013479111342008-11-30T00:49:00.004-07:002008-11-30T01:14:42.347-07:00Vim SneakinessOne of the things that I like most about Xcode is the auto-insertion of a closing curly-brace on the second line below whenever I enter an opening curly-brace, and the insertion of the cursor on the line in-between them. However, at heart I'm still a Vim guy, and tonight I got tired of actually typing that closing curly-brace. So, to make Vim automagically create my curly-brace blocks for me, I did the following.<br /><br />In my .vimrc, I place the following lines<br /><pre><br />if has("autocmd")<br /> autocmd FileType c source ~/.vim/brace.vim<br /> autocmd FileType cpp source ~/.vim/brace.vim<br /> autocmd FileType objc source ~/.vim/brace.vim<br /> autocmd FileType java source ~/.vim/brace.vim<br /> autocmd FileType pl source ~/.vim/brace.vim<br />endif<br /></pre><br /><br />brace.vim is very simple, containing only the following line:<br /><pre><br />imap { {<CR>}<Esc>O<br /></pre><br /><br />This causes typing a opening curly brace to immediately insert a Carriage Return character (equivalent to pressing return/enter) then inserts a closing curly-brace, then switching to command-mode and "typing" O to place an insert-mode cursor on a newly-inserted line above the closing curly-brace.<br /><br />If anyone has a better way to do this, I'm open to suggestions.Alexhttp://www.blogger.com/profile/13385489484617545171noreply@blogger.com1tag:blogger.com,1999:blog-7592502102239071169.post-44063842287339412122008-10-28T11:59:00.003-06:002008-10-28T12:16:06.650-06:00Here's a handy little tool I've used often...Problem: In several applications, I've found the need to pop up an alert/message window telling the application user that something went wrong, or that something they did wasn't kosher.<br /><br />Solution: NSRunAlertPanel. Little macros like this one are additional reasons I love programming for the Mac. But to make it a little more useful, I created a method call that makes a dummy alert with an ok button and a given message. It looks like this:<br /><pre><br /><code><br />-(void) displayAlert:(NSString*) alertMsg {<br /> NSRunAlertPanel(@"Alert", alertMsg, @"OK", nil, nil);<br />}<br /></code><br /></pre><br />The actual NSRunAlertPanel macro signature looks like this:<br /><pre><br /><code><br />NSRunAlertPanel(NSString *title,<br /> NSString *msgFormat,<br /> NSString *defaultButton,<br /> NSString *alternateButton,<br /> NSString *otherButton)<br /></code><br /></pre><br />Other parameters can be added to the method signature to create more full-featured alerts. I created the method solely to remove the NSRunAlertPanel call (which can be a big method call) from the logic of what I'm doing at the moment and replace it with a short method call that does what I want it to.Alexhttp://www.blogger.com/profile/13385489484617545171noreply@blogger.com0tag:blogger.com,1999:blog-7592502102239071169.post-75461543377943902162008-10-26T00:04:00.003-06:002008-10-26T00:42:25.102-06:00Publishing a Bonjour networking service with NSNetServiceSo I'm working on an undisclosed (but totally awesome) iPhone/iPod Touch app for CS 598R (a capstone/senior project class), and have developed the following procedure for publishing a Bonjour service. I'm posting it here so I can always know where to find code that does what I want.<br /><br />Feel free to use the code, just don't blame me if it doesn't do what you want it to...<br /><br />You can see the basic sample code <a href="http://pastie.org/300694">here</a>, or on the <a href="http://cocoaheads.byu.edu/">BYU CocoaHeads</a> site <a href="http://cocoaheads.byu.edu/wiki/publishing-nsnetservice-item-bonjour-networking">here</a>.Alexhttp://www.blogger.com/profile/13385489484617545171noreply@blogger.com0tag:blogger.com,1999:blog-7592502102239071169.post-10025409157997058402008-05-22T21:15:00.003-06:002008-10-25T23:57:04.077-06:00NSMutableArray makes awesome Cocoa stacks and queuesA difference between Java and Objective-C/Cocoa? Java has ConcurrentLinkedQueue, PriorityBlockingQueue, ArrayBlockingQueue, blah blah blah.<br /><br />Objective-C/Cocoa(or Foundation) has NSMutableArray. NSMutableArray has some nice instance methods that make it _extremely_ easy to build a queue, stack, priority queue (synchronized or otherwise) without loading up the API with a billion separate classes.<br /><br />Need a stack?<br /><code><br />-(void) push:(id) item {<br />[list addObject:item] // where list is the actual array in your stack<br />count++;<br />}<br /><br />-(id) pop {<br />id r = [list lastObject];<br />[list removeLastObject];<br />count--;<br />return r;<br />}<br /></code><br />How about a queue?<br /><br /><code><br />-(void) enqueue:(id) item {<br />[list insertObject:item atIndex:0];<br />count++;<br />}<br /><br />-(id) dequeue {<br />id r = [list lastObject];<br />[list removeLastObject];<br />count--;<br />return r;<br />}<br /></code><br />Priority queueing and/or synchronization for thread-safety will be left as an exercise for the reader. Man, I've always wanted to say that... :)Alexhttp://www.blogger.com/profile/13385489484617545171noreply@blogger.com8tag:blogger.com,1999:blog-7592502102239071169.post-24382545752450370382008-05-21T11:03:00.009-06:002011-07-20T12:52:45.874-06:00NSThreads when you need to wait.For my webserver project I need to use queues. The main thread places connections that need to be serviced in a queue. "Worker" threads need to place log entries in a queue to be written out to the log file. These queues obviously need to be thread-safe. Writing a thread-safe queue is quite simple thanks to the NSLock and NSConditionLock classes. Just like any other semaphore, you create a NSLock object and surround your critical section with:<br />
<code><br />
[myLock lock]<br />
<span style="font-style: italic;">critical section...</span><br />
[myLock unlock]<br />
</code><br />
The real question I had to deal with here, though, was thoroughly testing my queues to make sure that they were _really_ thread safe. Unlike POSIX threads, Cocoa/Foundation has no mechanism for waiting on NSThread objects. But I needed to know that all of my testing threads were finished before I started comparing expected and actual results. The solution is not that difficult. The entry point/run loop for an NSThread object is a method with the mandatory signature:<br />
<br />
<code>(void) threadFuncName:(id)</code><br />
<br />
So you create a struct or a class that has any data you need to pass in to your thread's main function. In addition, include in this struct or class an object of NSConditionLock. Immediately upon entry to the function, lock this with some condition code that will let your main program thread know that the thread is running. After spawning the thread, you want the main program execution to try and lock your condition lock when the run condition is no longer true. This will cause your main program thread to block and wait for your new thread to unlock with the condition you're waiting on. The last thing you'll want to do before your thread exits the run loop function is unlock the NSConditionLock with some condition that will let your main program thread know it's done. This will unblock your main thread of execution and you're off.<br />
Sample code: (not complete, just the snippets that you'll need)<br />
<br />
<pre><code>
#import <Foundation/Foundation.h>
#define NOT_DONE 0
#define DONE 1
// this will need to be on some class that is calling the NSThread object
-(void) someFunc:(id) arg {
NSConditionLock* myLock = arg;
[myLock lock];
//do stuff that we need to know about in main
[myLock unlockWithCondition:DONE];
}
int main() {
NSConditionLock* finishedLock = [[NSConditionLock alloc]
initWithCondition: NOT_DONE];
NSThread* myThread = [[NSThread alloc] initWithTarget:self
selector:@selector(someFunc:) object:finishedLock];
[myThread start];
[finishedLock lockWhenCondition:DONE];
// now we can do whatever we need to do with the results from
// the thread we spawned
}
</code>
</pre>Alexhttp://www.blogger.com/profile/13385489484617545171noreply@blogger.com5tag:blogger.com,1999:blog-7592502102239071169.post-2605153090374244232008-05-14T00:36:00.003-06:002008-05-14T00:44:47.285-06:00Is it love?<span style="font-family:courier new;">I've decided to use Objective-C and the Cocoa/Foundation frameworks to implement the main project for my internet programming class.<br /><br />My mission: to build a multi-threaded (yet limited functionality) webserver with CGI capability by the 3rd week of June.<br /><br />Pros:<br />1. I'd like to work for Apple someday, and building a webserver with their technology seems a good resume-booster.<br />2. Objective-C (with the Foundation/Cocoa frameworks) is a pretty nifty language with some good features that I'm quite keen to learn about<br />3. I'll be learning a lot, which I care much more about than grades<br /><br />Cons:<br />1. I'll be learning a lot, so I'm not likely to get an A in this particular class<br />2. I've had to do a lot of research on threading/synchronization so I'm a little behind on a project. (2 days, but who's counting?)<br />3. Learning the quirks of a new language means I'll be working at the last minute most of the semester, whereas if I just used C and POSIX threading/synchronization libraries I could probably whip this together pretty quickly.<br /><br />Is it love? I guess I'll know in a few weeks.<br /><br /></span>Alexhttp://www.blogger.com/profile/13385489484617545171noreply@blogger.com0tag:blogger.com,1999:blog-7592502102239071169.post-1021197795842366212008-03-18T11:59:00.004-06:002008-03-18T12:44:05.031-06:00AppleScript, Growl, and iCal<span style="font-weight: bold;">Problem: </span><br />After deciding that a little more organization would do me some good, I started using iCal. But I still kept forgetting due dates. Email notifications of iCal events were not much help, since I don't use a mail client with any frequency. I hated the message alarms from iCal, but I like Growl, and I especially like the idea behind <a href="http://hans.fugal.net/blog/articles/2008/02/15/cr%C3%A8me-rappel">Creme Rappel</a> (sorry, no accent marks here).<br /><br /><span style="font-weight: bold;">Solution:</span><br />So I started tinkering around with iCal's AppleScript dictionary. After a _lot_ of work, and lots of digging around the internets, I cobbled something together that fits the bill. The idea is that when an iCal alarm is triggered, you run an app that looks through your calendars to find the event that triggered an alarm within the current 2-minute window (leaving a little room for error) and tell Growl to tell you about it. You'll need Growl (included in .zip file) installed for this to work.<br /><br />Disclaimer: If you've got a lot of calendars and events, it will take a minute to churn through them. I'm working on a more efficient way to do this, but now that it's working, school is going to have to come first for a while.<br /><br />You can get iCalGrowl <a href="http://students.cs.byu.edu/%7Eae227/links/iCalGrowl.zip">here</a>.<br /><br />Screenshot:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2Grr53GGYMBpcMPjDkleqxOMww0QNGPd7n0Wa7xX71_UOs7omNR8srjSY01qwbPKy8a7Ctu85rO317lH2YyrANElEGraut1Fpxz2bU5YvCPUn5Y90s2Sy2cEjKgR4lR0QhbGpOYV-nmaE/s1600-h/iCalGrowl_scrnsht.jpg"><img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2Grr53GGYMBpcMPjDkleqxOMww0QNGPd7n0Wa7xX71_UOs7omNR8srjSY01qwbPKy8a7Ctu85rO317lH2YyrANElEGraut1Fpxz2bU5YvCPUn5Y90s2Sy2cEjKgR4lR0QhbGpOYV-nmaE/s320/iCalGrowl_scrnsht.jpg" alt="" id="BLOGGER_PHOTO_ID_5179153936239713682" border="0" /></a>Alexhttp://www.blogger.com/profile/13385489484617545171noreply@blogger.com0tag:blogger.com,1999:blog-7592502102239071169.post-65410008250354018282008-02-26T10:47:00.002-07:002008-02-26T10:49:22.751-07:00Monolingual: Handle With CareSo I learned something interesting about Monolingual today: If you remove all the PPC stuff from your universal binaries, you won't be able to build and link Xcode projects. So if you think you need to save the megabytes of disk space that trimming PPC code from universal binaries will get you, think again if you use Xcode.<br /><br />Or tell me how you worked around this.Alexhttp://www.blogger.com/profile/13385489484617545171noreply@blogger.com2tag:blogger.com,1999:blog-7592502102239071169.post-48755452918498422102007-08-30T20:42:00.000-06:002007-10-12T21:43:46.931-06:00Objective-C Syntax in gVimFor those who know me, it's no secret that I'm a Vim man. You know how some people are fish out of water without Visual Studio or (insert IDE here)? I'm a fish out of water without my .vimrc. Thanks to Vim's superior editing capabilities, I can get work done on any computer I need to as long as it at least has a basic Vim installation on it, but when I can use my own macros and settings, let the good times roll.<br /><br />The other day I decided that since I'm also a Mac man, I ought to start wrapping my head around Objective-C. So I got a book and started in. I quickly discovered that for some reason, Vim wasn't detecting the .m filetype extension for my Objective-C source files. So I did some digging around through the Vim documentation and found the following:<br /><br />You need in your home directory (or whatever your $VIMRUNTIME directory is) a directory named ".vim". Inside this directory you'll need to make a file called "filetype.vim". Paste the following into that file:<br /><table border="1"><br /> <tbody><tr><br /> <td><br /> <pre><br />"Check to see if the filetype was automagically identified by Vim<br /><br />if exists("did_load_filetypes")<br /><br /> finish<br /><br />else<br /><br /> augroup filetypedetect<br /><br /> au! BufRead,BufNewFile *.m setfiletype objc<br /><br /> augroup END<br />endif<br /></pre><br /> </td><br /> </tr><br /></tbody></table><br /><br />What happens, or at least what happened to me, is that for some reason Vim didn't automagically detect the ".m", or it was conflicting with another filetype for some reason. What the above snippet of vimscript does is ask Vim if it loaded a filetype. In my case, it hadn't. So it skips the "finish" command and moves to the "augroup" section, checking the file extension you gave the file (in this case ".m" and says, "oh hey, that's an Objective-C file", and then sets the filetype as such.<br /><br />Now I know that some of you may start yelling at me telling me that this is already there on Vim's documentation, blah blah blah. I posted this as a convenience for those who don't want to spend hours digging for it.Alexhttp://www.blogger.com/profile/13385489484617545171noreply@blogger.com6tag:blogger.com,1999:blog-7592502102239071169.post-72063578750575210182007-03-05T16:45:00.000-07:002014-04-10T22:48:45.469-06:00Is my Mac using too much memory???<div style="text-align: center;">
<span style="color: #990000;">Edit/Update: Modern releases of OS X (Mountain Lion and particularly Mavericks) treat memory much differently. I'm leaving this post as-is for historical reasons, but if you're running Mavericks you'll see things pretty differently.</span></div>
<br />
I have been a linux user for a few years, and I recently (6 months ago) switched to a MacBook. One of the reasons I originally switched from Windows to Linux was resource efficiency. There were others, but this is the one that leads to this discussion. A couple of weeks after I got my MacBook, I was working one day on a programming project for school with nothing open but iTerm and a couple of gvim windows. I happened to look at a resource monitor widget I had in my Dashboard, and was immediately concerned that I was only showing around 100 Mb free RAM. Concerned that I had some kind of memory leak going on I started digging around to find out where the "bug" was. It turns out that the bug was in my understanding of how OSX uses--and labels--memory. A friend of mine (Quinn) helped illuminate some of this for me. So here it is.<br />
<br />
If you open the Activity Monitor (found in utilities) and select the "System Memory" tab at the bottom, you'll see something that looks roughly like this:<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJtbGadnszm3GICxfMeqCrC0vZCXgQ2bR5Ju-Ao_XbXqQnxdi4VxvERW-UlROhY4_Zgu4CU6xv1XlEzddVIBSKR5GAgPp82uqlIgXNqNuUhwl2pW0Bdc44tctIok0BWstrFv8P-8NL3DNd/s1600-h/normal_small.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJtbGadnszm3GICxfMeqCrC0vZCXgQ2bR5Ju-Ao_XbXqQnxdi4VxvERW-UlROhY4_Zgu4CU6xv1XlEzddVIBSKR5GAgPp82uqlIgXNqNuUhwl2pW0Bdc44tctIok0BWstrFv8P-8NL3DNd/s400/normal_small.jpg" id="BLOGGER_PHOTO_ID_5039745342718927538" style="cursor: pointer; display: block; margin: 0px auto 10px; text-align: center;" /></a>OSX labels physical memory (RAM) as follows: Wired, Active, Inactive, and Free.<br />
<br />
Wired memory is used by the OS and is pretty much untouchable. Another application can't "borrow" wired memory.<br />
<br />
Active memory is what is currently in use by running applications. Note that thanks to the splendors of virtual memory, <span style="font-style: italic;">all</span> of the memory needed by an application isn't necessarily contained here. If you look at a running process in the Activity Monitor list, you'll see a column for <span style="font-style: italic;">Real </span>and a column for <span style="font-style: italic;">Virtual Memory.</span> Since we are talking about the amount of RAM in use, we won't worry about virtual memory for the moment. If there is no inactive, or free memory, active memory can be used by other applications, but this causes the OS to write the current state of the active memory being traded to its owner's virtual memory pages on disk before granting the memory to another application.<br />
<br />
Inactive memory is memory that has recently been used by an application that is no longer running. OSX keeps track of what this is and what it belonged to because of the idea of <span style="font-style: italic;">temporal locality</span>, the idea being that if you opened an application you are somewhat likely to do so again and if the memory is still labeled, the application can start very quickly. In the absence of sufficient free memory, inactive memory will be reclaimed by another running application that needs memory.<br />
<br />
Free memory is just that, free. Nothing has a claim on it, and it's up for grabs for any application that needs it.<br />
<br />
As you can see from my screen-shot image above, I tend to run with around 100-200 Mb free, between 150 and 300 Mb wired, and the rest split between active and inactive. What does this memory labeling have to do with how fast or slow the machine runs? Simple. When you log in, OSX claims the memory it needs to do all of its chores. This is wired. Other applications claim a smallish chunk of active memory as they are opened. Most applications that need to keep track of any kind of history or user data gradually use up more memory the longer they are open. Every now and then an application will need to use some part of its memory that it doesn't use frequently and OSX has to get this from disk and place it in that application's active memory allocation. All of these things can slow down a system. Also, virtualization applications such as Parallels or VMWare's Fusion require a large chunk of memory for the virtual machine that gets marked as wired.<br />
<br />
The main thing you want to be aware of is not necessarily how much memory you have marked as free, but how much wired, active, and inactive memory you have and how often OSX has to swap memory pages in from or out to disk (Page ins/outs in the Activity Monitor). For example, my MacBook (which has 1 Gb of RAM) is almost always very responsive, except when I'm running anything in a virtual machine. When I start up Windows (which happens as rarely as possible), Parallels grabs its virtual machine memory and my usage graph looks like this:<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggu1r4VdGFMy7ynb5ys-kHxppyKGDNQ2lyM6NsGszW6Dpmn12qgUM6vampkGIQXzRChfEfTZwfC5ZOggAluwLWQGmUnwN76QjGsEKpGdgbWfx6B8TTTUhfkPRNDo8E3ow2EA2ZkEPp_5sP/s1600-h/parallels_start_small.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggu1r4VdGFMy7ynb5ys-kHxppyKGDNQ2lyM6NsGszW6Dpmn12qgUM6vampkGIQXzRChfEfTZwfC5ZOggAluwLWQGmUnwN76QjGsEKpGdgbWfx6B8TTTUhfkPRNDo8E3ow2EA2ZkEPp_5sP/s400/parallels_start_small.jpg" id="BLOGGER_PHOTO_ID_5039745905359643330" style="cursor: pointer; display: block; margin: 0px auto 10px; text-align: center;" /></a>You'll notice that wired has more than doubled in size, there is significantly less inactive memory, and next to none free. Page ins/outs are ok. "Ins" has a pretty high count from a human standpoint, but it's no big deal. "Outs" is still pretty low and my system is still fairly responsive. However, if I then try to run lots of other applications, I run into problems.<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVl78XoZpJ3_3E_sY54bCC5Db1Cp8PmD-GVg63rIGBu-BmiQXMCTiCNKQoQ9Qa6bi_zznIHJWH7GePMKHNaRwJzpbl8NuCiTZzjfeq-gwhQUsNJsFKRDb4NwTIVDDk-9J8krRhxfZz6GvF/s1600-h/page_out_increase_small.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVl78XoZpJ3_3E_sY54bCC5Db1Cp8PmD-GVg63rIGBu-BmiQXMCTiCNKQoQ9Qa6bi_zznIHJWH7GePMKHNaRwJzpbl8NuCiTZzjfeq-gwhQUsNJsFKRDb4NwTIVDDk-9J8krRhxfZz6GvF/s400/page_out_increase_small.jpg" id="BLOGGER_PHOTO_ID_5040031163841011234" style="cursor: pointer; display: block; margin: 0px auto 10px; text-align: center;" /></a>Just opening Firefox caused the "Outs" to nearly double almost instantly. Inactive memory has gone down even more, and my system is noticeably less responsive. Continuing on this trend leads to a condition where "Ins" and "Outs" are nearly equal, and climbing fast. When this happens, OSX is spending all its time shuttling memory in and out of the virtual memory pages on disk, and doesn't have time to do much else. Similarly, your running applications are all waiting on OSX to swap memory to and from disk, and take much longer to do what you want them to do. This is bad. Closing the memory hogs in a condition like this will lead to almost instantaneous relief.<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjn1708me-ER9yNauHaulO8Z33XZB8uT6OAb8Zboog7zPAVs_JW1qAVvlqS1zbSxCVC6j4MGH-g2cUz7W2cDLO8vg_rTyM8Y9lL-8lTM3jutgxHYFvzaLged7WdfobQujuDHzmhf8I5o9QY/s1600-h/relief_small.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjn1708me-ER9yNauHaulO8Z33XZB8uT6OAb8Zboog7zPAVs_JW1qAVvlqS1zbSxCVC6j4MGH-g2cUz7W2cDLO8vg_rTyM8Y9lL-8lTM3jutgxHYFvzaLged7WdfobQujuDHzmhf8I5o9QY/s400/relief_small.jpg" id="BLOGGER_PHOTO_ID_5040031421539049010" style="cursor: pointer; display: block; margin: 0px auto 10px; text-align: center;" /></a>In this case, you'll notice that closing Parallels immediately caused a huge leap in free memory, and a marked decrease in active. This is sort of an isolated case in that the memory that was previously wired for the virtual machine is now free. In a normal case, closing applications like Photoshop, Office programs, etc. will cause a slower increase in free memory and a more immediate increase in inactive memory, with an additional decrease to active. It will take a little while for your system to get "balanced" again, and the more applications you close, the faster this will happen. You'll notice that in the time it took me to shut down my windows system running in Parallels, close Parallels, and take another screen-shot that page "Outs" increased by 9 times, and by proportion were rapidly gaining on page "Ins".<br />
<br />
The moral of the story is: If you happen to look at Activity Monitor or some other system resource monitor and notice that you only have about 10-15% of RAM free, don't worry about it unless your system is noticeably unresponsive. This is not to say that some third party applications don't have memory leaks, but that's a topic for another day.Alexhttp://www.blogger.com/profile/13385489484617545171noreply@blogger.com61