Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC dosen't care about code quality?

MFC dosen't care about code quality?

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++visual-studiocomlinux
9 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Naveen
    wrote on last edited by
    #1

    I have read in a book that, the worst thing you can do for "optimizing the storage of constant data" is declaring a variable like.. CString g_str("this is the worst thing I can do"); Why I said this here because, recently I installed Visual studio 2008 feature pack and today while debuggig, I happened to step into the base class( CWinAppEx ) of my app class. There I found the below code..

    CString strRegEntryNameWorkspace = _T("Workspace");
    m_strRegSection = strRegEntryNameWorkspace;

    With a little surprise, I scrolled the file, and in the top, there was another bunch of such declartions..

    static const CString strRegEntryNameControlBars = _T("\\ControlBars");
    static const CString strWindowPlacementRegSection = _T("WindowPlacement");
    static const CString strRectMainKey = _T("MainWindowRect");
    static const CString strFlagsKey = _T("Flags");
    static const CString strShowCmdKey = _T("ShowCmd");
    static const CString strRegEntryNameSizingBars = _T("\\SizingBars");
    static const CString strRegEntryVersion = _T("ControlBarVersion");
    static const CString strVersionMajorKey = _T("Major");
    static const CString strVersionMinorKey = _T("Minor");

    So pathetic :(

    nave [OpenedFileFinder]

    modified on Tuesday, April 29, 2008 10:26 AM

    D T L 3 Replies Last reply
    0
    • N Naveen

      I have read in a book that, the worst thing you can do for "optimizing the storage of constant data" is declaring a variable like.. CString g_str("this is the worst thing I can do"); Why I said this here because, recently I installed Visual studio 2008 feature pack and today while debuggig, I happened to step into the base class( CWinAppEx ) of my app class. There I found the below code..

      CString strRegEntryNameWorkspace = _T("Workspace");
      m_strRegSection = strRegEntryNameWorkspace;

      With a little surprise, I scrolled the file, and in the top, there was another bunch of such declartions..

      static const CString strRegEntryNameControlBars = _T("\\ControlBars");
      static const CString strWindowPlacementRegSection = _T("WindowPlacement");
      static const CString strRectMainKey = _T("MainWindowRect");
      static const CString strFlagsKey = _T("Flags");
      static const CString strShowCmdKey = _T("ShowCmd");
      static const CString strRegEntryNameSizingBars = _T("\\SizingBars");
      static const CString strRegEntryVersion = _T("ControlBarVersion");
      static const CString strVersionMajorKey = _T("Major");
      static const CString strVersionMinorKey = _T("Minor");

      So pathetic :(

      nave [OpenedFileFinder]

      modified on Tuesday, April 29, 2008 10:26 AM

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Naveen wrote:

      I have read in a book that, the worst thing you can do for "optimizing the storage of constant data" is declaring a variable like.. CString g_str("this is the worst thing I can do");

      Do you, or the book's author, have metrics to back this up?

      "Love people and use things, not love things and use people." - Unknown

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      N 1 Reply Last reply
      0
      • D David Crow

        Naveen wrote:

        I have read in a book that, the worst thing you can do for "optimizing the storage of constant data" is declaring a variable like.. CString g_str("this is the worst thing I can do");

        Do you, or the book's author, have metrics to back this up?

        "Love people and use things, not love things and use people." - Unknown

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        N Offline
        N Offline
        Naveen
        wrote on last edited by
        #3

        It is actually a microsft press release book :). Programming vc++ by David Kruglinski. And the reason is if you are writing some code like const char g_pch[] = "test"; the g_pch get stored in the .rdata section of the code. This section hold initialized readonly data. The more stuff you put in the .rdata section, the better because even multpile copy of application is running, no need to create seperate page file. If you wrote like const CString g_str("this is the worst thing I can do"); Now you've got the CString object (which is quite small) in the .bss section, and you've also got a character array in the .data section, neither of which can be backed by the EXE file. To make matters worse, when the program starts, the CString class must allocate heap memory for a copy of the characters. You would be much better off using a const character array instead of a CString object.

        nave [OpenedFileFinder]

        1 Reply Last reply
        0
        • N Naveen

          I have read in a book that, the worst thing you can do for "optimizing the storage of constant data" is declaring a variable like.. CString g_str("this is the worst thing I can do"); Why I said this here because, recently I installed Visual studio 2008 feature pack and today while debuggig, I happened to step into the base class( CWinAppEx ) of my app class. There I found the below code..

          CString strRegEntryNameWorkspace = _T("Workspace");
          m_strRegSection = strRegEntryNameWorkspace;

          With a little surprise, I scrolled the file, and in the top, there was another bunch of such declartions..

          static const CString strRegEntryNameControlBars = _T("\\ControlBars");
          static const CString strWindowPlacementRegSection = _T("WindowPlacement");
          static const CString strRectMainKey = _T("MainWindowRect");
          static const CString strFlagsKey = _T("Flags");
          static const CString strShowCmdKey = _T("ShowCmd");
          static const CString strRegEntryNameSizingBars = _T("\\SizingBars");
          static const CString strRegEntryVersion = _T("ControlBarVersion");
          static const CString strVersionMajorKey = _T("Major");
          static const CString strVersionMinorKey = _T("Minor");

          So pathetic :(

          nave [OpenedFileFinder]

          modified on Tuesday, April 29, 2008 10:26 AM

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #4

          i guess defining a **const** CString is somewhat different than defining a CString object. the optimizer certainly takes the constness in account more easily. interresting though.

          [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

          N 1 Reply Last reply
          0
          • T toxcct

            i guess defining a **const** CString is somewhat different than defining a CString object. the optimizer certainly takes the constness in account more easily. interresting though.

            [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

            N Offline
            N Offline
            Naveen
            wrote on last edited by
            #5

            May be, but not excatly what you get when you declare like const strRegEntryNameWorkspace[] =_T("Workspace"); and you see some of the variable declared are passed to functions which have LPCTSTR as parameter. Means they are not taking any advantage of the class CString :(

            nave [OpenedFileFinder]

            T 1 Reply Last reply
            0
            • N Naveen

              May be, but not excatly what you get when you declare like const strRegEntryNameWorkspace[] =_T("Workspace"); and you see some of the variable declared are passed to functions which have LPCTSTR as parameter. Means they are not taking any advantage of the class CString :(

              nave [OpenedFileFinder]

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #6

              hum, yes, I answered a bit too fast too... even a const CString, the compiler doesn't really know what the CString class is for, so if you need literals, it's obvious that you have to use const TCHAR*s... or at best, use the resource string table.

              [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

              1 Reply Last reply
              0
              • N Naveen

                I have read in a book that, the worst thing you can do for "optimizing the storage of constant data" is declaring a variable like.. CString g_str("this is the worst thing I can do"); Why I said this here because, recently I installed Visual studio 2008 feature pack and today while debuggig, I happened to step into the base class( CWinAppEx ) of my app class. There I found the below code..

                CString strRegEntryNameWorkspace = _T("Workspace");
                m_strRegSection = strRegEntryNameWorkspace;

                With a little surprise, I scrolled the file, and in the top, there was another bunch of such declartions..

                static const CString strRegEntryNameControlBars = _T("\\ControlBars");
                static const CString strWindowPlacementRegSection = _T("WindowPlacement");
                static const CString strRectMainKey = _T("MainWindowRect");
                static const CString strFlagsKey = _T("Flags");
                static const CString strShowCmdKey = _T("ShowCmd");
                static const CString strRegEntryNameSizingBars = _T("\\SizingBars");
                static const CString strRegEntryVersion = _T("ControlBarVersion");
                static const CString strVersionMajorKey = _T("Major");
                static const CString strVersionMinorKey = _T("Minor");

                So pathetic :(

                nave [OpenedFileFinder]

                modified on Tuesday, April 29, 2008 10:26 AM

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                CString and optimization should never be used in the same sentence. It is common sense that constant string literals is a more optimized way of storing string literals. There seems to have been a paradigm shift over the years that optimizations are no longer valid. Its funny how Moore's law has accurately predicted the number of transistors and Wirth's law[^] is correctly predicting that applications are increasingly becoming slower and slower. I have noticed that many software engineers excessively use CStrings and have no concept of passing values through the stack rather than the heap. It is my opinion/philosophy that software engineers should be certified sort of like a doctor or lawyer. We should all be dressed in lab coats and wearing einsteins haircut[^]. Flame away! -David Delaune

                B B 2 Replies Last reply
                0
                • L Lost User

                  CString and optimization should never be used in the same sentence. It is common sense that constant string literals is a more optimized way of storing string literals. There seems to have been a paradigm shift over the years that optimizations are no longer valid. Its funny how Moore's law has accurately predicted the number of transistors and Wirth's law[^] is correctly predicting that applications are increasingly becoming slower and slower. I have noticed that many software engineers excessively use CStrings and have no concept of passing values through the stack rather than the heap. It is my opinion/philosophy that software engineers should be certified sort of like a doctor or lawyer. We should all be dressed in lab coats and wearing einsteins haircut[^]. Flame away! -David Delaune

                  B Offline
                  B Offline
                  BadKarma
                  wrote on last edited by
                  #8

                  Randor wrote:

                  CString and optimization should never be used in the same sentence. It is common sense that constant string literals is a more optimized way of storing string literals. There seems to have been a paradigm shift over the years that optimizations are no longer valid. Its funny how Moore's law has accurately predicted the number of transistors and Wirth's law[^] is correctly predicting that applications are increasingly becoming slower and slower.

                  This problem will only grow. Especially with the new .Net languages where you don't need to worry about the memory. I've recently used c# to create a report, due to the enormous data to put into the report the memory it used was about 1 GB. After I closed the report, the memory wasn't freed. I though no problem, thats why there is a Garbage Collector running. Yeah right, tried to create the report again and the OutOfMemoryException was thrown. I rather stick with c/c++ where I can control the memory, in such way I need or see fit.

                  Randor wrote:

                  I have noticed that many software engineers excessively use CStrings and have no concept of passing values through the stack rather than the heap. It is my opinion/philosophy that software engineers should be certified sort of like a doctor or lawyer. We should all be dressed in lab coats and wearing einsteins aircut[^].

                  I like this idea :-D, We certainly need safety goggles too and a light saber, in case we are attacked by a lowlife BUG ;P

                  codito ergo sum

                  1 Reply Last reply
                  0
                  • L Lost User

                    CString and optimization should never be used in the same sentence. It is common sense that constant string literals is a more optimized way of storing string literals. There seems to have been a paradigm shift over the years that optimizations are no longer valid. Its funny how Moore's law has accurately predicted the number of transistors and Wirth's law[^] is correctly predicting that applications are increasingly becoming slower and slower. I have noticed that many software engineers excessively use CStrings and have no concept of passing values through the stack rather than the heap. It is my opinion/philosophy that software engineers should be certified sort of like a doctor or lawyer. We should all be dressed in lab coats and wearing einsteins haircut[^]. Flame away! -David Delaune

                    B Offline
                    B Offline
                    bob16972
                    wrote on last edited by
                    #9

                    Randor wrote:

                    I have noticed that many software engineers excessively use CStrings and have no concept of passing values through the stack rather than the heap

                    I'm confused. Are you saying you pass a CString on the stack or the heap? Where is the object? Where is the string? What exactly are you saying here?

                    Randor wrote:

                    CString and optimization should never be used in the same sentence.

                    I beg to differ(And so does Mr. DiLascia)... http://www.microsoft.com/msj/archive/S1F0A.aspx[^]

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups