Developing application for mobile devices such as pocket PC or mobile phone is very interesting, I am feeling excited while developing applications target to compact framework. Mobile devices are memory constraint devices it is very important for every developer to pay attention on efficient memory utilization and application performance. Recently I got few mails from developers to know how to leverage performance of mobile device application? In this article I am sharing few recommendations which we are using in our day to day development activity of compact framework based applications.
We are extensively using base class library collection classes to store a group of objects, if we store any value type in collection class lets say storing int into ArrayList, causes overhead of boxing and unboxing, to avoid this it is better to define a custom class and make the value type as member variable and store the class instance in an ArrayList. We can take the advantage of generics in compact framework 2.0 to avoid boxing/unboxing and up-casting/down-casting of collection objects.
Another important pointer regarding collection class is to pre-size the collection before inserting objects to it. It is recommend to define the size of collection class rather than depending upon the default size (default capacity of ArrayList is 4). Once your collection grows beyond the default capacity, it gets resized frequently depending up on the type of object storage and the auto expansion of collection is a overhead process, the recommend solution is pre-size the collection class before use. Similarly use FOR instead of FOREACH because foreach involves sequence of virtual method (GetEnumerator(), get_Current(), and MoveNext()) calls through IEnumerator interface.
Virtual method call is a performance overhead for your application because virtual methods are never inlined by JIT when a virtual method gets call, compact framework walks the class and interfaces hierarchy looking for requested method by name and call signature, other performance overhead is it is approximately two time slower then static and instance method call. If you need a virtual call the best thing is to implement functionality as much as you can in a single virtual method rather than splitting into multiple methods and do not make most frequently called methods as virtual. Similarly PInvoke and COM method calls are 6 time slower then managed instance method calls, native method call is faster than instance method call. It is recommend to design your class based on the above statistics to leverage performance.
If you are using structure and calling ToString() or Equal() method it is better to override these methods otherwise it leads to boxing & un-boxing issue.
Santhakumar MunuswamyPosted Dec 1, 2015, 3:14 AM
Good One
anurag beheraPosted Sep 9, 2009, 1:23 AM
how to set different resolution of mobile web site as per browsing device screen resolution