|
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
|
|
|
|
|
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.
|
|
|
|
|
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 , We certainly need safety goggles too and a light saber, in case we are attacked by a lowlife BUG
codito ergo sum
|
|
|
|
|
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[^]
|
|
|
|
|
i am working in vc8 in win32. now i am changing my code to windows mobile5.0. all things worked fine, except for time.
i have used only minimal time functions in that.
they are
1. localtime 2.gmtime 3.ctime 4.mktime 5.time
i have converted localtime, and mktime. but for others i dont have any idea about how to port other functions.
please help me to port it...
RAJA
|
|
|
|
|
You have the source to each of these functions. Why not look there?
"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
|
|
|
|
|
Hi EveryOne,
I have added a class which contains a method that accepts a VARIANT type variable in an ActivexDll written in VC++. In one of sample code I found the a value is assigned to the VARIANT type variable using a SAFEARRAY. My question is how can a string value be assigned to VARIANT type variable(type casting in strcpy does't work). Can we achieve it only by using SAFEARRAY? if yes why is it so? Is there any other way to obtain the same? kindly explain. Thank you.
Regards,
LG.
lgatcodeproject
|
|
|
|
|
Probably you should use a BSTR insted.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Hi,
Even if I use the BSTR type while copying a string constant using strcpy with a type cast the application crashes. How to copy a string constant by-passing this problem?
Please find the below snippet.
<br />
STDMETHODIMP CRAPClientX::Connect(BSTR serverIP, BSTR serverPort,BSTR output)<br />
{<br />
strcpy((char *)output, "connected");<br />
return S_OK;<br />
}<br />
Regards,
LG.
lgatcodeproject
|
|
|
|
|
lgatcodeproject wrote: STDMETHODIMP CRAPClientX::Connect(BSTR serverIP, BSTR serverPort,BSTR output)
{
// TODO: Add your implementation code here
strcpy((char *)output, "connected");
return S_OK;
}
Change to
STDMETHODIMP CRAPClientX::Connect(BSTR serverIP, BSTR serverPort,BSTR * pOutput)
{
*pOutput = SysAllocString(L"connected");
return S_OK;
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Hi,
Thanks its working now but then I have a doubt, what is that L do inside SysAllocString()function.
Regards,
LG.
lgatcodeproject
|
|
|
|
|
A BSTR is substantially a wide char string (technically it is a OLECHAR one). the L prefix creates a wide char literal.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
There are too many string types you can use in your VC++ project.
STL and many other non-MS libs use string class; MFC prefers CString; when it comes to COM, you will see _bstr_t and BSTR. ……
Many code in my project just do string conversions——convert from one string type to another, which makes me fell ugly.
Hello everyone, which is your favorite string type?
A Chinese VC++ programmer
|
|
|
|
|
I mainly use STL string unless I have to use CString for when working with MFC. Never did any COM programing so never used _bstr_t or BSTR.
-Saurabh
|
|
|
|
|
STL's basic_string template class is much more flexible in this respect and allows you to create any kind of the strings suitable for specific scenarios.
You can use CString if the size of the project is going to be small. In case the project is a large one than I would rather prefer a wrapper class to encapsulate all the functionality and use it.
BSTR's are used in COM.It's better to convert the CString to a _bstr_t and then pass it to the COM interface if you are working with COM since they have to maintain compatibility with VB datatypes and components can be invoked from there.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Thank you! Your suggestion is very constructive.
I do like STL's basic_string, but I have to use its c_str() memfunc when I pass a string object to MFC classes.
A Chinese VC++ programmer
|
|
|
|
|
TCHAR*
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
I believe you're not serious
A Chinese VC++ programmer
|
|
|
|
|
You're wrong.
(Well, I often have to use one or more of the classes you were talking about, but usually I prefer going to the metal)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
I know what you're mean.
Thank you!
A Chinese VC++ programmer
|
|
|
|
|
|
Ozer Karaagac wrote: Maybe, you may want to consider this.
No. That is so old and ugly stuff. Most of it is even for VC6!
And look at the second picture (the one named "Screenshots of native C++ equivalent") and how his class MLFString has a equals()-member!
Somone who programs JAVA in C++ is not someone to whose programming tip I tend to listen!
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
Three negative votes against just sharing an article without revealing any acceptance.
Isn't it somewhat harsh? What a great liking to vote negative?
Is this STL fanaticism? If so, good luck to you with your lovely STL.
In STL we trust.
|
|
|
|
|
I don't really like any of them, but use whatever fits best into the current project. For instance, now I work on something with lots of COM, so I use CComBSTR. On the previous job, we were making an OS-portable system, so the obvious choice was std::string.
|
|
|
|