Presentation is loading. Please wait.

Presentation is loading. Please wait.

Advanced Managed Code Development Features Marcus Perryman

Similar presentations


Presentation on theme: "Advanced Managed Code Development Features Marcus Perryman"— Presentation transcript:

1 Advanced Managed Code Development Features Marcus Perryman marcpe@microsoft.com

2 Agenda Compact Framework Detail Compact Framework Detail  Under the hood!  Performance  Interop Using CF in the Real World Using CF in the Real World  Graphics  Forms management  Web Services Summary Summary

3 Compact Framework Detail

4 The EE A short review Compiled managed code is a binary in Microsoft Intermediate Language Compiled managed code is a binary in Microsoft Intermediate Language Code is just-in-time compiled to the native processor language on type-by-type, method-by-method basis Code is just-in-time compiled to the native processor language on type-by-type, method-by-method basis Resulting native code is cached for later reuse Resulting native code is cached for later reuse Over the lifetime of the app, the up front cost of jitting is amortized, and becomes less and less significant Over the lifetime of the app, the up front cost of jitting is amortized, and becomes less and less significant

5 Per-Thread Control Flow ExecuteManagedMethod JITCompiled? Verify & JIT CompileMethod Load Base Classes Locate “Main” Class Class Execute Native (Until next Method) Yes LoadContainingClass No OtherClasses? Load Other Class Yes -Parents -Containing called methods -Declaring Args, Locals, Fields -Allocated (new) Jump to Native Code Return to CLR

6 Under the Hood Build process Build process  Same compilers  Local exe produced – additional Deploy step File format File format  Standard PE format with no native code  Module load upgraded on device  Contains Intermediate Language (IL) blocks  Resources bound in or deployed in parallel Deploy Deploy  Uses Connection Manager not Platform Manager  Again over Active Sync

7 .NET Compact Framework System System.DataSystem.Xml System.Web Globalization Text Security Collections Resources Reflection Net IO Threading Diagnostics ServiceProcess Configuration Design ADO.NET SqlServerCe SqlClient Xslt/XPath XmlDocument Runtime InteropServices Remoting Serialization Serialization ConfigurationSessionState CachingSecurity Services Description Discovery Protocols UI HtmlControls WebControls System.Drawing Imaging Drawing2D Text Printing System.WinForms DesignComponentModel Reader/Writers

8 Unsupported Excluded Supported Pocket PC NETCF Controls ButtonCheckBoxComboBoxContextMenuDataGridDomainUpDownFileOpenDialog HScrollBarImageListLabelListBoxListViewTreeViewTrackBarFileSaveDialogMainMenuNumericUpDownPanelPictureBoxProgressBarInputPanel GroupBox Printing Controls RichTextBox NotificationBubble (PPC) RadioButtonStatusBarTabControlTextBoxTimerToolBarVScrollBar CheckedListBoxColorDialogErrorProvider HelpProviderLinkLabel NotifyIconToolTip ToolTipSplitterFontDialog

9 Framework Size Framework size (RAM or ROM) Framework size (RAM or ROM)  ~1.5 MB Running RAM needs Running RAM needs  1 MB+ (depends on app) Typical application sizes Typical application sizes  5 - 100 KB  Apps often smaller due to use of platform features in the framework

10 ILDASM Multiple environments

11 Active Sync Connection Manager Remote Deploy And Debug Visual Studio.NET Windows DebugManager Device or Emulator STREAM CONNECT Process Enumerate App.exe File Copy App.pdb App.exe Remote Exec STREAM CONNECT Remote Debug

12 Garbage Collection Desktop: G 0G 1G 2 2k Mark Promote Mark Promote

13 Garbage Collection Compact Framework : 5K Threshold MarkCompact Pitch Code? LRU

14 Performance

15 What Is Performance? Affected by two principles Affected by two principles  Absolute Performance of the system; the raw processing horsepower  Apparent Performance of the application; affected by how the application is written Application performance is qualitatively measured by how responsive the application is to the end user

16 Code Pitching Occurs when large volumes of allocated memory cause memory pressure Occurs when large volumes of allocated memory cause memory pressure Runtime will discard or pitch code from the code cache Runtime will discard or pitch code from the code cache Qualitative inspection will tell you when this occurs Qualitative inspection will tell you when this occurs

17 Behavior Under Memory Pressure Memory utilization Performance

18 Performance User Interface: User Interface:  Version 1 performance is excellent!  System.Drawing and System.Windows.Forms call to native APIs beneath  Call “batching” where possible  Pools and reuses Window Handles Data And XML Performance Data And XML Performance  Version 1 performance is good  Mostly implemented in managed code  Memory pressure effect data performance Compact Framework SP2 Compact Framework SP2  Improved performance everywhere  Most notable with XML DOM

19 Interop

20 Overall Native Code Interop strategy Focus on enabling versus exhaustive Focus on enabling versus exhaustive  PInvoke is powerful, but advanced or edge case scenarios are more difficult than the desktop  It is possible for COM and.NET components to peacefully coexist in the same process/thread Focus on simplicity for Version 1.0 Focus on simplicity for Version 1.0  Native code interop is very fast and simple Compact Framework V2.0 Compact Framework V2.0  Adds Com Interop  Rich marshaling – Layout of structures

21 Marshaling Of Simple Types The execution engine marshaling of simple data types The execution engine marshaling of simple data types C# Visual Basic Native Code intInteger int (32-bit integer) shortShort short (16-bit) boolBoolean BYTE (8-bit)* charChar wchar (16-bit) StringString wchar * Array int [] Array Integer () Data of the Array int * longLong Not Supported (64-bit) doubleDouble Not Supported (floating point) *bool and Boolean DO NOT convert to a Win32 BOOL

22 Marshaling Complex Objects Marshal class Marshal class  Located in System.Runtime.InteropServices  Provides advanced functionality to customize marshaling Allows you to get copy managed objects into native code Allows you to get copy managed objects into native code Allows you to read and write raw memory if needed Allows you to read and write raw memory if needed

23 Callbacks No support for direct native to managed function calls No support for direct native to managed function calls Use MessageWindow Use MessageWindow  Part of Microsoft.WindowsCE.Forms Steps for Callback Steps for Callback  Create a MessageWindow in Managed  Pass window handle to native  Native sends messages back with it  Managed code can trap window messages

24 Using the Compact Framework

25 Common Application Features Using Graphics for Business Applications Using Graphics for Business Applications Dealing with Form Management Dealing with Form Management Being Smart about Web Services Being Smart about Web Services

26 Graphics System.Drawing System.Drawing  Supports GDI functions  (line, circle, rectangle etc…)  Good performance  Business application graphics  Wire frame diagrams Games API Games API  No DirectX support (coming soon)  Fast screen access  Sound, hardware buttons

27 More advanced graphics Speed Considerations Speed Considerations  Delayed draw protected override void OnPaint(PaintEventArgs e) { buffer = new Bitmap(Width, Height); Graphics g = Graphics.FromImage(buffer); // … Calculate new position PostRender(g); // Call post rendering routines... g.Dispose(); // Clean up... // Draw to display... e.Graphics.DrawImage(buffer, 0, 0); }  Double buffering  Sprites  Exclusion drawing http://smartdevices.microsoftdev.com/Learn/Articles/660.aspx#netcfgaming_topic4

28 Custom Controls Provides encapsulation and code sharing Provides encapsulation and code sharing No support for User Controls No support for User Controls Derive class from Control: Derive class from Control: public class Visualizer : Control protected override void OnPaint(PaintEventArgs e) Creating the Control: Creating the Control: // Create the 3D warehouse visualizer... this.visualizer = new Warehouse3D(); this.Controls.Add(this.visualizer); Installing to the designer Installing to the designer  Include RuntimeAssemblyAttribute [assembly:System.CF.Design.RuntimeAssemblyAttr ibute”…”)]  Requires desktop build of the control

29 Form Management The Form Flow Challenge The Form Flow Challenge  No Multiple Document Interface  Multi form input more common  Which form to display next?  Hide or destroy current form? Solutions Solutions  Dynamic form construction  Forms manager  Wizard based input (e.g. tight scripting of forms)

30 Form Management Application Kernel Web Service Interface Local Store (SQL CE ) Main FormCollect Form Inspect Form Truck Form Form Manager Main

31 Being Smart about Web Services Mobile Communication challenges Mobile Communication challenges  Latency, speed, coverage (we are mobile)  Chatty vs monologue? Consider interface to MapPoint Consider interface to MapPoint  Request the Lat / Long for start and end address FindAddress(startAddress); FindAddress(endAddress)  Request map or driving directions GetMap(mapspec)CalculateSimpleRoute(...) Chatty / State full breaks Store and Forward model Chatty / State full breaks Store and Forward model Monologue ==(?) Performance issues Monologue ==(?) Performance issues Consider a server Agent Consider a server Agent Agent.GetMapData(start,end,GET_MAP | GET_DIRECTIONS)

32 Summary Windows Mobile 2003 offers a rich and robust platform on which to build and deploy Mobile applications. Windows Mobile 2003 offers a rich and robust platform on which to build and deploy Mobile applications. Microsoft Visual Studio.NET 2003 provides state of the art development tools for targeting the Compact Framework. Microsoft Visual Studio.NET 2003 provides state of the art development tools for targeting the Compact Framework. The Compact Framework brings Mobile devices to the mainstream development community. The Compact Framework brings Mobile devices to the mainstream development community.

33 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.


Download ppt "Advanced Managed Code Development Features Marcus Perryman"

Similar presentations


Ads by Google