Memory Usage

Member
Posts: 31
Joined: 2009.01
Post: #1
Is there any calls to check overall memory usage at runtime? I'm trying to tape together my first app and seem to hit OOM. How much RAM does our apps get to run in?

Does the class numbers in my project have an effect on the executable size at runtime like j2me?

Are there any rules of thumb for dealing with memory in the iphone?

Thanks in advance
Quote this message in a reply
Member
Posts: 31
Joined: 2009.01
Post: #2
Does anyone have any idea on this? I seem to be running out of memory on the iPhone hardware, but I'm not doing a ton of allocations or anything. I'm a little confused as to why new is failing...
Quote this message in a reply
Moderator
Posts: 3,570
Joined: 2003.06
Post: #3
Learn to use Instruments to measure what is going on in your app in terms of memory usage/leaks/allocations. We've already had a few discussions on this in the past, so be sure to search the forums.

Nobody seems to have been able to get a concrete number out of Apple, but the general consensus that I've seen is that your app will have best luck somewhere in the 10 to 25 MB range (and the lower the better, of course).
Quote this message in a reply
Member
Posts: 31
Joined: 2009.01
Post: #4
I have used the instruments pretty extensively. I wanted to hook up memory reporting from another code base I had written, but have no idea about metrics avaliable at runtime outside of the tools...
Quote this message in a reply
Member
Posts: 93
Joined: 2008.11
Post: #5
calling "new" is btw not the right way to do your allocations in obj-c... or you use c++ instead?
Quote this message in a reply
Member
Posts: 31
Joined: 2009.01
Post: #6
Yes I cut right to the chase and use c++. I only use obj-c when I HAVE to, in which case I don't use new. I've been using c++ for years and saw no real good reason I'd use objective c over c++.

Maybe I'm wrong? Not sure which executes faster, I'd guess c++...
Quote this message in a reply
Moderator
Posts: 3,570
Joined: 2003.06
Post: #7
There's nothing wrong with using plain C or C++ and only using as much Obj-C as you need. I use plain C for 90% of my iPhone programming.

C++ is technically faster than Objective-C, but we're not talking about much. Objective-C uses a messaging system runtime which gives it great power and flexibility, but that comes at a very slight performance hit. There are ways to optimize calls and make it as fast as anything else (down to a pointer call), but that isn't done much in practice -- because it isn't usually necessary.
Quote this message in a reply
Member
Posts: 45
Joined: 2008.04
Post: #8
The following tells you how many wired/active/inactive/free pages there are:
Code:
mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
vm_statistics_data_t vmstat;
host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmstat, &count);

The following tell you the pagesize (in bytes):
Code:
int mib[] = {CTL_HW, HW_PAGESIZE};
int pagesize;
int length = sizeof(pagesize);
sysctl(mib, 2, &pagesize, &length, NULL, 0);

and {CTL_HW, HW_PHYSMEM}, and {CTL_HW, HW_USERMEM} give physical and user memory...

There's probably more - this stuff is generic and should work equally well on desktop and iphone.
Quote this message in a reply
Moderator
Posts: 3,570
Joined: 2003.06
Post: #9
Here's some more sysctl stuff (source link at bottom): http://furbo.org/2007/08/21/what-the-iph...-tell-you/
Quote this message in a reply
Member
Posts: 31
Joined: 2009.01
Post: #10
This is exactly what I was looking for. Thanks!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  RAM usage sealfin 14 6,768 Oct 20, 2010 04:02 PM
Last Post: Applewood
  host_statistics memory usage output confusing kendric 0 3,704 Jan 11, 2010 02:50 AM
Last Post: kendric
  How much memory usage is too much? Gillissie 8 5,767 Oct 8, 2009 04:08 AM
Last Post: Madrayken
  Guideline for Memory Usage aarku 7 4,440 Dec 27, 2008 07:19 AM
Last Post: jaguard
  How do you determine memory usage? green_ghost 5 4,277 Sep 8, 2008 09:01 PM
Last Post: green_ghost