Performance Improvements to VC++ in VS 2008

Since I deal with a large VC++ of native-managed code I am glad to see Somasegar's list of VC++ performance enhancements in Visual studio 2008

· Editor responsiveness – Updating IntelliSense, displaying the QuickInfo tooltip and processing AutoComplete requests won’t degrade editor experience.

· Goto Definition improvements – Significant reduction in the time required to “Goto Definition”.  One customer reported that a 2 minute delay dropped to 10-20 seconds.

· Load solution performance – Load time of large Visual C++ solutions is much better.  Some customers are reporting speed ups of 25%-70%.

· File lookup in projects – Provides improvements to several scenarios such as adding files to projects, changing configurations, etc.

· Changing configuration options – Modifying options, such as adding an include directory or changing the active configuration, are much faster for large solutions.

· Reduced CPU consumption – We now process low-priority background items (such as IntelliSense population) using 20% less CPU time.

I have had to deal with slow IntelliSense and solution load times. All of these issues affect my daily use of VS.  Its great that the VC++ is finally able to address them.  Its even better to hear there will be a patch for VS 2005.

Comments [0]

A case of the AWAL Destructor.

Is it a Memory leak or a Resource leak.

It would seem that if you take a c++ managed extensions gc class containing a native pointer to dot net 2.0.  The classes finalization does not happen correctly.  Ie the destructor is no longer invoked.

further more if you migrate said c++ code to c++/cli then your destructor will not get called when the managed object is disposed of via garbage collection.  You will need to either explicitly call the destructor or add a finalize to your reference class.

 

Not the most obvious memory leak in the world to say the least.

Comments [0]

Macros For converting C++ extensions to cli

Public Module ConversionModule

    Public Sub UpdateToCLI()

        SeachAndReplaceDocumentPointers("System::")

        SeachAndReplaceDocumentPointers("nsoftware::IPWorksSSL::IPWorksSSLException")
        SeachAndReplaceDocumentPointers("nsoftware::IPWorksSSL::HttpsStatusEventArgs")
        SeachAndReplaceDocumentPointers("nsoftware::IPWorksSSL::HttpsStatusEventArgs")
        SeachAndReplaceDocumentPointers("C1::Win::C1FlexGrid::")
        SeachAndReplaceDocumentPointers("C1::")

        FindReplace("__gc ", "ref ")
        FindReplace("__property", "property")
        FindReplace("__try_cast", "safe_cast")
        FindReplace(" S""", " """)
        FindReplace("(S""", "(""")
        'FindReplace("    S"",""")

        NewToGCnew("System") 
        NewToGCnew("nsoftware")
        NewToGCnew("C1FlexGrid")
        NewToGCnew("C1::")


        ReplaceTypeOf()
        ReplaceItemOf()
        FindReplace("->ItemOf", "->default")
        FindReplace("->Item", "->default")


    End Sub

    Sub SeachAndReplaceDocumentPointers(ByVal ManagedNameSpaceToken As String)

        SeachAndReplacePointers(ManagedNameSpaceToken + "*\*", "^")
        SeachAndReplacePointers(ManagedNameSpaceToken + "\*", "^")
        SeachAndReplacePointers(ManagedNameSpaceToken + "*^ &", "%")
        SeachAndReplacePointers(ManagedNameSpaceToken + "*^&", "%")
        SeachAndReplacePointers(ManagedNameSpaceToken + "*^ \*", "%")
        SeachAndReplacePointers(ManagedNameSpaceToken + "*^\*", "%")
    End Sub
    Sub SeachAndReplacePointers(ByVal What As String, ByVal ReplaceWith As String)
        Do
            DTE.Windows.Item(DTE.ActiveDocument.Name).Activate()
            DTE.Find.FindWhat = What
            DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
            DTE.Find.MatchCase = False
            DTE.Find.MatchWholeWord = False
            DTE.Find.Backwards = False
            DTE.Find.MatchInHiddenText = False
            DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxWildcards
            DTE.Find.Action = vsFindAction.vsFindActionFind
            If (DTE.Find.Execute() = vsFindResult.vsFindResultNotFound) Then
                Exit Do
            Else
                DTE.ActiveDocument.Selection.CharRight()
                DTE.ActiveDocument.Selection.DeleteLeft()
                DTE.ActiveDocument.Selection.Text = ReplaceWith
            End If
        Loop

    End Sub
    Sub FindReplace(ByVal What As String, ByVal ReplaceWith As String)
        DTE.Find.Action = vsFindAction.vsFindActionReplaceAll
        DTE.Find.FindWhat = What
        DTE.Find.ReplaceWith = ReplaceWith
        DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
        DTE.Find.MatchCase = False
        DTE.Find.MatchWholeWord = False
        DTE.Find.MatchInHiddenText = False
        DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxWildcards
        DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone
        DTE.Find.Action = vsFindAction.vsFindActionReplaceAll
        DTE.Find.Execute()
    End Sub
    Sub NewToGCnew(ByVal Type As String)

        Do
            DTE.Find.FindWhat = " new " + Type + "*"
            DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
            DTE.Find.MatchCase = False
            DTE.Find.MatchWholeWord = False
            DTE.Find.Backwards = False
            DTE.Find.MatchInHiddenText = False
            DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxWildcards
            DTE.Find.Action = vsFindAction.vsFindActionFind
            If (Not (DTE.Find.Execute() = vsFindResult.vsFindResultNotFound)) Then
                DTE.Find.Action = vsFindAction.vsFindActionReplace
                DTE.Find.ReplaceWith = " gcnew "
                DTE.Find.FindWhat = " new "
                DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
                DTE.Find.MatchCase = False
                DTE.Find.MatchWholeWord = False
                DTE.Find.Backwards = False
                DTE.Find.MatchInHiddenText = False
                DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxWildcards
                DTE.Find.Execute()
            Else
                Exit Do
            End If
        Loop
    End Sub
    Sub ReplaceTypeOf()
        Do
            DTE.Find.FindWhat = "__typeof(*)"
            DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
            DTE.Find.MatchCase = False
            DTE.Find.MatchWholeWord = False
            DTE.Find.Backwards = False
            DTE.Find.MatchInHiddenText = False
            DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxWildcards
            DTE.Find.Action = vsFindAction.vsFindActionFind
            If (Not (DTE.Find.Execute() = vsFindResult.vsFindResultNotFound)) Then
                DTE.ActiveDocument.Selection.CharLeft()
                DTE.ActiveDocument.Selection.CharRight(True, 9)
                DTE.ActiveDocument.Selection.Delete()

                DTE.Find.FindWhat = ")"
                DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
                DTE.Find.MatchCase = False
                DTE.Find.MatchWholeWord = False
                DTE.Find.Backwards = False
                DTE.Find.MatchInHiddenText = False
                DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxWildcards
                DTE.Find.Action = vsFindAction.vsFindActionFind
                If (Not (DTE.Find.Execute() = vsFindResult.vsFindResultNotFound)) Then
                    DTE.ActiveDocument.Selection.Text = "::typeid"
                End If
            Else
                Exit Do
            End If
        Loop
    End Sub
    Sub ReplaceItemOf()
        Do
            DTE.Find.FindWhat = "get_ItemOf"
            DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
            DTE.Find.MatchCase = False
            DTE.Find.MatchWholeWord = False
            DTE.Find.Backwards = False
            DTE.Find.MatchInHiddenText = False
            DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxWildcards
            DTE.Find.Action = vsFindAction.vsFindActionFind
            If (Not (DTE.Find.Execute() = vsFindResult.vsFindResultNotFound)) Then
                DTE.ActiveDocument.Selection.Delete()
                DTE.ActiveDocument.Selection.Text = "default["

                DTE.Find.FindWhat = ")"
                DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
                DTE.Find.MatchCase = False
                DTE.Find.MatchWholeWord = False
                DTE.Find.Backwards = False
                DTE.Find.MatchInHiddenText = False
                DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxWildcards
                DTE.Find.Action = vsFindAction.vsFindActionFind
                If (Not (DTE.Find.Execute() = vsFindResult.vsFindResultNotFound)) Then
                    DTE.ActiveDocument.Selection.Text = "]"
                End If
            Else
                Exit Do
            End If
        Loop

    End Sub
    Sub WrapCStringWithSystemString()

        DTE.ActiveDocument.Selection.Text = " gcnew System::String( " + DTE.ActiveDocument.Selection.Text + " )"
    End Sub
    Sub WrapSystemStringWithCString()

        DTE.ActiveDocument.Selection.Text = " CString( " + DTE.ActiveDocument.Selection.Text + " )"
    End Sub
    Sub WrapValueArray()
        DTE.ActiveDocument.Selection.Text = "array< " + DTE.ActiveDocument.Selection.Text + " > ^"
    End Sub
    Sub WrapHandle()
        DTE.ActiveDocument.Selection.Text = "(HWND)" + DTE.ActiveDocument.Selection.Text + ".ToPointer()"
    End Sub
    Sub ConvertToNull()
        DTE.Find.Action = vsFindAction.vsFindActionFind
        DTE.Find.FindWhat = "NULL"

        DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
        DTE.Find.MatchCase = False
        DTE.Find.MatchWholeWord = False
        DTE.Find.MatchInHiddenText = False
        DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxWildcards
        DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone
        DTE.Find.Action = vsFindAction.vsFindActionFind
        DTE.Find.Execute()
        DTE.ActiveDocument.Selection.Text = "nullptr"
    End Sub
    Sub updateDefaultI()
        DTE.Find.Action = vsFindAction.vsFindActionFind
        DTE.Find.FindWhat = "default(i)"

        DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
        DTE.Find.MatchCase = False
        DTE.Find.MatchWholeWord = False
        DTE.Find.MatchInHiddenText = False
        DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxWildcards
        DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone
        DTE.Find.Action = vsFindAction.vsFindActionFind
        DTE.Find.Execute()
        DTE.ActiveDocument.Selection.Text = "default[i]"
    End Sub
    Sub UpdateToGCNew()

        DTE.Find.Action = vsFindAction.vsFindActionFind

        DTE.Find.FindWhat = " new "
        DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
        DTE.Find.MatchCase = False
        DTE.Find.MatchWholeWord = False
        DTE.Find.Backwards = False
        DTE.Find.MatchInHiddenText = False
        DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxWildcards
        DTE.Find.Execute()
        DTE.ActiveDocument.Selection.Text = " gcnew "

    End Sub
    Sub UpdateHat()

        DTE.Find.Action = vsFindAction.vsFindActionFind

        DTE.Find.FindWhat = "\*"
        DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
        DTE.Find.MatchCase = False
        DTE.Find.MatchWholeWord = False
        DTE.Find.Backwards = False
        DTE.Find.MatchInHiddenText = False
        DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxWildcards
        DTE.Find.Execute()
        DTE.ActiveDocument.Selection.Text = "^"

    End Sub
    Sub UpdateHatAndGcNew()
        UpdateHat()
        UpdateToGCNew()
    End Sub
End Module
Comments [0]

Some Links for Moving Between C++ Versions or to C#

If your moving MFC or C++ extensions to dot net 2.0 here are a few items you might find useful

Comments [1]

Daylight Saving Time has Changed- don't be caught off guard.

Last night I got a letter from MSDN.  If you have been in away and missed it the Daylight Saving Time has changed read on to see what might be affected if you use DOT NET or CRT.

Dear Valued Microsoft Customer,
In 2005, the United States government passed the Energy Policy Act of 2005. This act changes the start and end dates for Daylight Saving Time (DST) as of spring 2007. These changes may impact the way applications run. Microsoft is releasing an update for Windows through Microsoft Update that reflects these changes.
Developers who use the .NET Framework may find their applications affected if the application uses the time zone information for historical purposes or if they have derived custom classes from System.TimeZone to provide custom time zone information. The standard System.TimeZone class provides a managed wrapper for the underlying Windows Operating System time zone functions.
In addition, developers who use Visual C++ may find their applications affected if they use the CRT time functions, or the TZ environment variable. Microsoft is currently working on a fix for this issue and will post information about its availability on the Visual Studio Support page.
Most applications that use these affected classes will not need to be modified as this update will ensure that the correct data is provided seamlessly to the application. However, applications that use these classes or the underlying Windows API to perform historical time look-ups will need to be modified.
In most cases, developers who have extended the .NET Framework’s time zone support by creating custom time zone classes derived from System.TimeZone, or by direct access to the Win32 API, will not have to update their applications as long as the available updates to the operating system are applied. However, solutions that rely on private time zone data, or that retrieve system time zone information by accessing the registry directly, may need to be updated. Applications that deal with historical time zone data may also need to be updated.
Microsoft advises all developers who make use of time zone data to test their applications against this update to ensure that their applications function correctly.
For more detailed information and the latest updates please visit http://msdn2.microsoft.com/en-us/vstudio/bb264729.aspx, Preparing for daylight saving time changes in 2007, and KB928388: 2007 time zone update for Microsoft Windows operating systems


Update: I corrected all links.
Comments [0]

Can't open a Visual studio 2003 project?

If you receive the following message from visual studio 2003

---------------------------
Microsoft Development Environment
---------------------------
Project .vcproj' failed to open.
---------------------------
OK  
---------------------------

you can open your *.vcprog file with your favorite xml editor and find the "/VisualStudioProject/References/AssemblyReference" nodes make sure all the paths and files are valid.  One will not be, remove it or edit the path save the file and now open it in Visual Studio.

Comments [1]

VS 2005 Build to the prior frame work

Why is it possible to target a different version of the DotNet framework? and is it a good idea? If so why can we not do this for the MFC library as well?
Comments [0]

VS 2005 Pain Solved!

As it turns out, If you define and implement your whole class/structure in a .h file a consumer needs to mark it #pragma unmanaged.  If you don't delete will get confused and issue the errors i received from my earlier post.

Comments [1]

This is embarrassing

With one little mistake comes a nasty memory leak.  We found this in some of the code i wrote

CMenu* CLMI::GetLenderMenu(void)
{
    //test if lender should show up if not
    if ( !ShowLender() )
        return NULL;

    CMenu* clm = new CMenu();......


Sadly clm was never reclaimed, and MFC redraws the Main menu every time you blink so can you say bad :(

Comments [0]

VS 2005 pains

This is interesting, I am moving a vc++ project to VS 2005.  When i run it in debug mode i receive this error:

---------------------------
Microsoft Visual C++ Debug Library
---------------------------
Debug Assertion Failed!

Program: c:\Dev\Point\PointMain\Debug\Winpoint.exe
File: dbgdel.cpp
Line: 52

Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.


This I can trace back to the call to delete in this function:

    void RemoveIt(CDlgAncItem* item)
    {
        if (item)
        {
            RemoveIt(item->next);
            delete(item);
        }
    }

The CDlgAncItem is a class it has a destructor and a copy constructor.  I am not sure why the debugger is losing track of the memory, Its a pretty simple data structure stored in a dynamically allocated link list.
Edit: I found a solution.
Comments [0]