Blue Theme Orange Theme Green Theme Red Theme
 
Team Foundation Server Hosting
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
6 Months Free & No Setup Fees ASP.NET Hosting!
Search :       Advanced Search »
Home » Compact Framework » Best Practices of Compact Framework

Best Practices of Compact Framework

In this article I am sharing few recommendations which we are using in our day to day development activity of compact framework based applications.

Page Views : 18605
Downloads : 0
Rating :
 Rate it
Level : Intermediate
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
Team Foundation Server Hosting
Become a Sponsor
Discover the top 5 tips for understanding .NET Interop
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

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.

Direct field access is faster than having property call because property is nothing but getter and setter methods. The simple properties are inlined by JIT but this assumption may not work always if it involves virtual setter/getter method call or any complex operation. In order to inline a method your application must have the IL code less then 16 bytes, no branching ( typically "if"), no local variables, no exception handler etc. It is not possible to predict 100% accuracy whether a method will be inlined or not, method inlining never occurred if your application is running under debug mode. So if we can keep performance critical methods as simple as possible then there might be a chance for method inlining.

We frequently use DateTime in our application development, to leverage the performance of DateTime store it in binary format using ticks but local times are exception to this recommendation, for DateTime serialization if you know the exact format it is better to specify parsing. Take the advantage of DateTime.ParseExact() to avoid DateTime parser to apply sequential culture specific format to date and time string. The same rule is applicable to numeric parsing also.

For GUI performance, try to reduce number of method calls during initialization and for certain controls you need to do manual modification of design generated code to leverage performance. Always try to use BeginUpdate() & EndUpdate() for ListView and Tree View. Use SuspendLayout/ResumeLayout while repositioning controls. For GUI performance I recommend to refer

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/netcfimproveformloadperf.asp

Consuming web services is overhead for compact framework based applications because compact framework uses reflection mechanism to examine the service's proxy and it never cache this result which usually full compact framework does. It is strongly recommended to not to have multiple instances of the same web service in order to increase the performance of web service. Try to maintain a single global instance of the web service, avoid sending datasets over Web Service, because it pulls in a large amount of XML and uses complex algorithm for loading data. If you are sending/receiving a DataSet, ensure the schema is serialized alternatively or manually serialize dataset as an XML string before making web service call.

For compact framework performance related information please refer

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Anand Kumar
I am having 3 yrs of experience on .NET environment .My core expertise is developing robust service components using ATL COM ,Remoting and Web Service and very much passionate about Microsoft Patterns and Practices and .NET performance . Apart from my regular work I am actively participating various Microsoft User Groups and sharing my knowledge and articles.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the top 5 tips for understanding .NET
Ricky Leeks presents the top 5 tips for understanding .NET Interoperability. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Team Foundation Server Hosting
Become a Sponsor
 Comments
mobile web site resolution issue by anurag On September 9, 2009
how to set different resolution of mobile web site as per browsing device screen resolution
Reply | Email | Modify 
6 Months Free & No Setup Fees ASP.NET Hosting!
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.