MFC dosen't care about code quality?
-
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
-
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
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
-
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
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 likeconst 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]
-
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
i guess defining a
**const** CString
is somewhat different than defining aCString
object. the optimizer certainly takes the constness in account more easily. interresting though.[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
i guess defining a
**const** CString
is somewhat different than defining aCString
object. the optimizer certainly takes the constness in account more easily. interresting though.[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
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]
-
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]
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]
-
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
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
-
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
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
-
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
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[^]