So one of the most difficult things about being an iPhone programmer is figuring out just how darn much memory you’re actually using. And by way of this post on leak finding in an iPhone app, here’s a snippet for accomplishing that:
#import <mach/mach.h>
#import <mach/mach_host.h>
static void print_free_memory () {
mach_port_t host_port;
mach_msg_type_number_t host_size;
vm_size_t pagesize;
host_port = mach_host_self();
host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
host_page_size(host_port, &pagesize);
vm_statistics_data_t vm_stat;
if (host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size) != KERN_SUCCESS)
NSLog(@"Failed to fetch vm statistics");
/* Stats in bytes */
natural_t mem_used = (vm_stat.active_count +
vm_stat.inactive_count +
vm_stat.wire_count) * pagesize;
natural_t mem_free = vm_stat.free_count * pagesize;
natural_t mem_total = mem_used + mem_free;
NSLog(@"used: %u free: %u total: %u", mem_used, mem_free, mem_total);
}
If your application has non-trivial memory needs, you might be well served to bring that up at launch and tell the user to reboot if memory is low, for instance!
Colophon:
For Day 1 of The Great WordPress Client Test, this post is brought to you by:
Blogo 1.2.8!
Assuming, you know, you’re actually reading this, it does indeed set up and work transparently with WordPress 2.8, but there’s a few things that less than thrilled us:
- We’re not overly impressed with the HTML it produces compared to the online editor. We found extraneous paragraphs and the like once uploaded and we noticed that it broke the #include statements.
- Switch from rich text to HTML mode and back, or to edit mode and back, and you can’t undo. The online editor gets that right.
- Pasting and formatting that code snippet had a variety of associated annoyances; pasting in the wrong place, thinking the #includes were followed by tags or something. Eventually we deformatted the copied text in TextEdit and pasted it into the HTML view to get it to not do things wrong. That’s worse than the online editor too.
- We’re just not really fans of the interface. Maybe it grows on you.
- It completely failed to post the above picture — we added that online after posting!
- It ate the filenames in the #include statements during upload, apparently thinking they were HTML tags; we fixed that manually with the online editor. It should be smarter about sorting that kind of thing out.
- It mucked up the assigned categories when posting, and we fixed that manually too.
So there’s a number of reasons to look skeptically at it, and that picture problem is pretty much a dealbreaker, since we do like to put the odd picture in our posts. On the plus side, it does have a lot of nifty conveniences, the previous post editing looks nicely worked out and the setup guidance was a veritable exemplar of how to get people started properly … but we’re just not terribly thrilled with it overall. Out of ten, we’ll give it a four, and if someone happens to know The Magic Trick We’re Missing for getting the embedded picture to upload, then we’d give it a seven. But we’re certainly hoping that the remaining six work out better, even if the image upload fail is something easily correctable … because if not, sticking with the online editor is looking like a better idea.
JUL

Pingback: Tools: WordPress Clients at Under The Bridge