Monotouch Read how much RAM is left on an iPad - xamarin.ios

Using Monotouch, or Objective-C, how do I tell how much RAM is left on an iPad?

As far as I know there is no way to get the amount of RAM available.
You can handle low memory warnings by subscribing to an event.
In your "Main.cs"
public override void ReceiveMemoryWarning(UIApplication application)
{
// Do what you want to free memory
}
Not sure if this helps but given the lack of answers it may prove helpful.

Related

Virtual Memory in Visual C++

I have a query regarding Virtual Memory. First of all, I would like to mention that I am new to the field of programming. I have read up on Visual Memory.
Now I have a program which opens softwares which require large amounts of memory (like for example a picture viewer). The concerned computer, however, cannot spare that much of memory for this . And this is all done with Visual C++. The picture viewer is currently running on physical memory.
But once this software is distributed, it will be used on computers which cant spare that much of physical memory. So my task is to research and find out how to switch this program from using physical memory to virtual memory. In the end I will probably be implementing this myself.
So my question is, how do I alter the code in such a way that I can prevent the application from using physical memory and instead, switch over to virtual memory?
I'm not asking for someone to provide me with a copy paste code ofcourse, but just a method to do so. Also, if someone could explain the logic behind it, I would appreciate it.
Loads of thanks in advance.
The operating system is in charge of deciding what should be stored in RAM and what should be paged out to VM. Under certain abnormal circumstances, it can be useful to can provide advice to the OS from your app, but this is only recommended for experts. As a novice, your best bet is to trust that the OS will do the right thing.
Why do you think you need special behavior anyway? Pictures are generally small anyway. Unless your app is dealing with thousands and thousands, they will fit in RAM.
You can't use virtual memory without using some physical memory. There's a reason for the name swapfile. The processor cannot directly operate on data in secondary storage, such as hard disks. It must first copy it into RAM.

Windows CE (RTOS) class-libraries for latency of interrupts and threads and USB?

I am getting started in working with Windows CE to utilize RTOS to reduce latency concerns with interrupts and threads and USB. What class-libraries(visual c++) can you point me to that would be good to have learned well to speed up the learning curve?
Thanks
That's a really, really broad question. The most important piece of advice I'll give you is that if you're after determinism and speed (your reference to an RTOS leads me to think you consider these important) then you need to be aware that any memory allocation or deallocation in a piece of code makes it non-deterministic.
C++ classes often have allocations and deallocations buried in them, so whatever you choose (and whatever you write), use them wisely. Sometimes they'll allow you to provide custom allocators (e.g. Boost) which you can use to just pull memory from an already allocated heap you create somewhere.
Keep the real-time parts of the code as small and simple as possible.

Is there an official reference stating that battery life is one of the reasons why a Garbage Collector was not included inside iOS?

In the following SO question, it is mentionned that the Garage Collector was not included in iOS in order to conserve battery power.
Is there an offical reference from Apple stating that battery life is one of the reasons why a Garbage Collector was not included inside iOS?
I have been looking for it on google but was not able to find anything relevant.
... stating that battery life is one of the reasons why a Garbage Collector was not included inside iOS?
I would call that either good PR or agressive fanboyism. A good GC adds little overhead, especially no amount of overhead anyone would have to be concerned about. Problem is that Apple doesn't have a good garbage collector.
Objective-C's garbage collector is conservative and doesn't do compaction, which means that applications will leak memory over time and if you have a long-running app on your phone it will eventually eat up all available memory and crash. Actually that's the reason Apple recommends not using it for long-running tasks even on Mac OS X.
There is definitely also a major problem with unpredictable performance on all limited resouce devices. A colleague and mine were hired by Intel for the Pentim 3 launch to make some hefty UI stuff that showcased the AWESOME power of this processor so that everybody would upgrade.
For some reaon it was decided that a Java-based 3D interface to the Excite search engine was the ultimate solution. Planets with moons would represent result pages and individual search results. Space age stuff. This was obviously before the big internett ka-blam when people had way too much money and grand vision of a 3D cyberworld.
Well, the garbageman always popped in at the wrong time and frequently, so we did what we had to do back then and ask for a ton of memory and write our own allocation stuff. The client had no tolerance for jumpy GFX.
That did the trick, dirty as it may seem today.
I maintain that Apple's decision has most to do with little memory availabe plus wanted optimal, even speed in apps and games. They are not the kind of people who are happy with people going "argh, now it˙s lagging again."
I refer you to the recent hooplah around 4.x being dog slow on some devices. The new update kicked out some features to trade off for performance.

view virtual memory usage visually while debugging

This might be a big ask, but are there any tools that let me view the virtual memory usage of my process in Linux? I am talking detailed, probably graphical view of memory, including what is going into the reserved addresses, the BSS/text/etc segments, heap, stack growth, etc, while I am stepping over the program in a debugger?
I once used pmap to monitor memory consumption. It helped me a lot in discovering the source of a memory leak. It's far from being graphical but you can learn quite a lot from it.
Good question. For broad views, maybe just keep dumping /proc/pid/maps? I think pmap, mentioned above, shows info from here. But I guess you are talking about specific small allocs/deallocs.

How does iOS solve memory fragmentation?

I couldn't find any documentation about memory management of iOS. Especially about memory fragmentation. If you know any document about this, please let me know.
Memory fragmentation correction is an implementation detail. You should never, in any way, directly deal with it. However if you are worried that your objects will be moved around without notifying your code, don't; apple never moves objects - end of story. Once memory is allocated, it's yours (even if a framework class's instance is occupying it) until it is deallocated. That being said, from an academic perspective I see no reason why the iPhone shouldn't use at least a similar strategy to MacOS, on which there is an excellent article here.

Resources