Results 1 to 12 of 12

Thread: Performance: Managed vs. Unmanaged Code

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2007
    Location
    Netherlands
    Posts
    43

    Performance: Managed vs. Unmanaged Code

    Hi all,

    I want to create a pretty data intensive app for storing/searching sports stats and stuff, using VB.NET/SQLCE 3.0. Also since i want it to have a Today plugin i've started learning VC++ wich is, needless to say, pretty more complex than vb.net.

    My question is: is it worth while learning all that stuff to gain performance especially regarding DB stuff and POOM. For ex. i have a function that adds all the races/matches for the coming 12 months as appointments in POOM. This takes 5+ minutes to complete (1033 appointments) on the emulator. Another example is retrieving a record from the DB with, say, 5000+ entries. Wich also imho take too long for the user( i must say i have not yet really optimized this stuff, caching the sqlceresult for ex.).

    So would this in unmanaged code be any (signifacantly) faster and would the extra overhead of handling memory, longer dev. time, etc etc. be worth while ?

  2. #2
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Performance: Managed vs. Unmanaged Code

    Hi,
    don't judge performance from the emulator - it isn't real life. You can only judge on a device.
    Provided your table is indexed, your search should be quick.

    In my opinion, for such an app, managed code should be fine.
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  3. #3
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Performance: Managed vs. Unmanaged Code

    It's all about time.
    If you have the time to learn VC++ then...
    Another issue is that in every new CF more and more managed code is added.
    So if you try hard to do something in C++, even in the mobile Api's and the next framework is released witch does what you want....Then again you would have gained some knowledge on lower levels of programming.

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2007
    Location
    Netherlands
    Posts
    43

    Re: Performance: Managed vs. Unmanaged Code

    Thanks for the input, i have also tried it on a device (HTC Wizard @ 249mhz) and its still very slow, SQL does its job pretty fast indeed but the adding and removing of appointments just takes ages.

    Another weird thing is the loop that adds the appointments seems to get slower and slower the more appointments are added(i update/invoke a progressbar after each added appointment). Say the first 50 go at about 5 appointments a sec, the next 50 at 2 a sec. etc. till in the end it takes about 2-3 seconds per appointment.

    The code for removing the appointments (around 2 minutes):
    Code:
            'Load Race Appointments
            RaceAppointments = OutLook.Appointments.Items.Restrict("[Categories] = " & ControlChars.Quote & "Race" & ControlChars.Quote)
            'Delete Rac Appointments
            RaceAppointments.Clear()
    Code for adding (around 6 minutes):
    Code:
            SqlCom.CommandText = "SELECT RaceName,  StageType, StageDate, Division, Flag, NumberStages, StageNr FROM Stages " & _
                                           "INNER JOIN Races ON Stages.IDRace = Races.IDRace " & _
                                           "INNER JOIN Countrys ON Races.IDCountry = Countrys.IDCountry"
            Dim SqlDr As SqlCeDataReader
            SqlDr = SqlCom.ExecuteReader
    
     While SqlDr.Read
    
                Me.Invoke(New EventHandler(AddressOf UpdateProgress))
    
                StageType = Main.MyFunctions.GetTypeStage(SqlDr.Item(1))
    
    
                With Appointment
                    Subject.Length = 0
                    Subject.Append(SqlDr.Item(0))
    
                    .AllDayEvent = True
                    .Categories = "Race"
                    .ReminderDialog = False
                    .Properties.Add("Flag")
                    .Properties.Add("StageType")
                    .Subject = Subject.ToString()
                    .Properties.Item("Flag") = SqlDr.Item(4)
                    .Properties.Item("StageType") = StageType
                    .Start = CDate(SqlDr.Item(2))
                    .End = CDate(SqlDr.Item(2))
                End With
    
                AddedCount += 1
                OutLook.Appointments.Items.Add(Appointment)
    
            End While
            MsgBox("Appointments Added: " & AddedCount)
    @Sapator; that is indeed true, but does MS intend to drop VC++ for WM altogether in the future ?

  5. #5
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Performance: Managed vs. Unmanaged Code

    VC++ will always be there but what microsoft is doing easy make it easier for vb programmers in every new version.
    May i suggest that you also try in the hand classes for your window app. I have used them in the past for storring items and they work pretty fast.

  6. #6

    Thread Starter
    Member
    Join Date
    Feb 2007
    Location
    Netherlands
    Posts
    43

    Re: Performance: Managed vs. Unmanaged Code

    Could you explain what you mean by 'in the hand classes' ? I've thought about eliminating poom altogether and just store it in a sql db but i'd like to have it integrated with the pocket pcs appointments without the need for a custom application to show these dates.

  7. #7
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Performance: Managed vs. Unmanaged Code

    Hi,
    www.inthehand.com - have classes for dealing with POOM
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  8. #8

    Thread Starter
    Member
    Join Date
    Feb 2007
    Location
    Netherlands
    Posts
    43

    Re: Performance: Managed vs. Unmanaged Code

    Found it, tried it, and unfortunatly it failed adding appointments. Since im a hobbyist $199,- is too much for me anyway. Altough it seems to be just a native wrapper for poom. I'll have to find another solution im afraid, thanks for the input though

  9. #9
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Performance: Managed vs. Unmanaged Code

    I remember that somewhere was a hudge C# program that used for POOMing and relied in dllimports from the c++ poom wrapper class. I have tried it but i had a problem with the PPC simulator so i dropped it.
    So what i want to say is. Don't reinvent the wheel. There are Poom samples for C++. You can use them and add them to C# or VB.net.

  10. #10
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Performance: Managed vs. Unmanaged Code

    You may want to have a look on MSDN and the internet for
    POOMWrapper
    and
    POOMWrapperSampleSetup

  11. #11

    Thread Starter
    Member
    Join Date
    Feb 2007
    Location
    Netherlands
    Posts
    43

    Re: Performance: Managed vs. Unmanaged Code

    I've found the sample you were reffering to, unfortunatly it didn't work, couldn't add the reference to my project. Maybe beceause it was a PPC 2003 project where poom used CEDB instead of EDB, but that's just a guess though.

    However, i did manage to create my own DLL from the Pimstore.tlb. After experimenting some i got it too work. I have not done a proper test but with the code example below it feels 10x as fast as the managed route . So im very happy.

    For future reference, this was the article i used (goto excercise 2). The code i have so far (just for testing):

    Code:
    Public Sub DoDit()
    
            Try
    
                Dim Outlook As ApplicationClass
                Outlook = New PocketOutlook.ApplicationClass
                Outlook.Logon()
    
                If MessageBox.Show("Delete data ?", "Delete or add", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) _
                    = DialogResult.Yes Then
    
                    Dim CalendarFolder As PocketOutlook.Folder = Outlook.GetDefaultFolder(OlDefaultFolders.olFolderCalendar)
    
                    Dim aAppointment As AppointmentItem
                    Dim DeleteAppointments As New List(Of AppointmentItem)
                    'For i As Int16 = 0 To CalendarFolder.Items.Count - 1
                    '    Dim asAppointment As PocketOutlook.IAppointment = CalendarFolder.Items.Item(i)
                    '    asAppointment.Delete()
                    'Next
    
                    For Each aAppointment In CalendarFolder.Items
                        DeleteAppointments.Add(aAppointment)
                    Next
    
                    For Each aAppointment In DeleteAppointments
                        aAppointment.Delete()
                    Next
    
                    UpdateList()
        
                Else
    
                    Dim CalendarFolder As PocketOutlook.Folder = Outlook.GetDefaultFolder(OlDefaultFolders.olFolderCalendar)
                    Dim aAppointment As AppointmentItem
    
                    For i As Int16 = 0 To 150
                        aAppointment = CalendarFolder.Items.Add
                        aAppointment.Subject = "Race: " & i
                        aAppointment.Start = DateTime.Today
                        aAppointment.Categories = "Race"
                        aAppointment.Save()
                    Next
    
                    UpdateList()
    
                End If
    
                Outlook.Logoff()
    
            Catch ex As COMException
                MessageBox.Show(ex.Message)
            Catch ex As System.Exception
                MessageBox.Show(ex.Message)
            End Try
    
        End Sub
    There are some quirks i still need to figure out, for ex. deleting items directly from a (appointment) collection can't be done by calling the CalendarFolder.Items.Item(i) (as you can see i commented them out and replaced it by filling an array with the items first and then calling .Delete on them all one by one.

  12. #12
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Performance: Managed vs. Unmanaged Code

    Tried to incorporate it in to the old POOM c# project but it says that it cannot add reference. Using it into the new project worked.
    Well my company bought inthehand classes so i'm just fooling around now, but i guess it's good to have this articles for reference for other programmers.

    P.S. Thanks for the feedback
    Last edited by sapator; Nov 28th, 2007 at 05:03 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width