|
Hi
STL string class "substr" method allocates on the heap? I was watching memory window that seems to be true - that the returned string has an entirely different address (relative to input string)
<br />
string str("Hello");<br />
...<br />
str.substr(lastPos, pos - lastPos)<br />
Thanks!
|
|
|
|
|
From MSDN substr() page ...
Return Value
A substring object that is a copy of elements of the string operand beginning at the position specified by the first argument.
It IS a copy. Different implementations of the STL handle allocating memory for strings differntly but there is a good chance its allocating memory on the heap.
With most versions of Visual Studio you get the full source code for the STL so you could easily answer this yourself with some investigation
|
|
|
|
|
Does anyone know what API I can use to determine the CPU time used by a process? This is not the same as elapsed time!
Yours Truly, The One and Only!
|
|
|
|
|
Alright it seem the GetProcessTimes API does what I was looking for
Yours Truly, The One and Only!
|
|
|
|
|
You can also use PDH library for this.
AJay
|
|
|
|
|
Great! Thanks Ajay, I will keep this in mind for future uses.
Yours Truly, The One and Only!
|
|
|
|
|
Hi,
I'm using a C++(native) in VS2005. And when I manually add some member variables or methods the intellisence can't handle this and when I'm trying to build the application(MFC executable) it crushes the VS2005 IDE.
After that I've to manually delete the intellisence database file (*.ncb) and open solution for compilation again.
The question is:
- Is there any way (some hot key or IDE macro) to enforce manually intellisence update from the VS2005 IDE?
This would solve my problem.
Thanks,
Oleg.
|
|
|
|
|
Hey Friends
I rememeber we had a way by which we can monitor changes in a folder.
I even implemented it long time back.
i do not remember anything about it now
Any idea of the api / way ?
Regards
|
|
|
|
|
Check out FindFirstChangeNotification() and ReadDirectoryChangesW()
|
|
|
|
|
Brilliant
Thanks
|
|
|
|
|
vikrant kpr wrote: I rememeber we had a way by which we can monitor changes in a folder.
ReadDirectoryChangeW[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
|
Hello,
I have to find how change the menu background color (menubar and menuitems), but nothing yet.
On true, I want to change my dialog based app background color (I am using SetDialogBkColor() method), but the menu (I have a menu in the dialog too) continue with the default system background color.
So, I only want to change the menu background color (same color of my dialog background).
Could anybody help me?
Thanks,
Cris.
|
|
|
|
|
Cris wrote: SetDialogBkColor
... is obsolete. Handling WM_CTLCOLOR is a better choice into the future.
For the menus, maybe take a look at deriving a class from CMenu and making the menu owner drawn.
See here[^] for lots of examples.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
Hi,
I need to convert TCHAR to char*.
TCHAR buff[512]={NULL};
char tempBuff[512]={NULL};
CString strTemp;
_stprintf(buff, _T("Hello World"));
strTemp = buff;
buff = strTemp.GetBuffer(strTemp.GetLength());
but buff seems to be null.
I'm unable to convert from TCHAR to char*. Using VC++6.0/MFC. UNICODE VERSION.
Thanks in Advance.
Rajesh
|
|
|
|
|
Rajesh_Parameswaran wrote: buff = strTemp.GetBuffer(strTemp.GetLength());
You can't convert a TCHAR* to a TCHAR[512] so that assignment won't work.
What are you trying to do? Do you need to convert the contents of the
TCHAR array to an array of char or just cast the pointer to the array to a different type?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I didn't notice your tempBuff variable, so I assume you want something like this:
TCHAR buff[512]={NULL};
char tempBuff[512]={NULL};
_stprintf(buff, _T("Hello World"));
strcpy(tempBuff, CT2CA(buff)); Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Use an ATL conversion macro:
CString s = _T("Hello world!");
const char* p = T2CA(LPCTSTR(s)); More here[^] and here[^]
|
|
|
|
|
Mike,
That doesn't work on VS 2005 which is why I coded my example like I did (besides
trying to fit the OP's code).
How does one force the macros to work old-style like you've shown?
Thanks,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
What about it doesn't work in VC8? Does CT2CA work instead?
|
|
|
|
|
|
I found it - need a macro.
USES_CONVERSION;
CString s = _T("Hello world!");
const char* p = T2CA(LPCTSTR(s));
That's better
To recap:
USES_CONVERSION;
CString s = _T("Hello world!");
const char* p1 = CT2CA(LPCTSTR(s));
const char* p2 = T2CA(LPCTSTR(s));
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark/Micheal,
Thanks for the response.
I'm still having problem in using the macro USES_CONVERSION.
I'm not using ATL in my project.
Could you let me know an alternative solution with VC++6.0 / MFC?
thanks in advance,
Rajesh
|
|
|
|
|
Hi Rajesh,
Michael's solution should work for VC++ 6. It will NOT work on VC++ 8, so you may want to keep
that in mind if you ever plan to migrate to a new version of C++.
*EDIT* Actually, it WILL work, but you'll need to add the USES_CONVERSION macro in VC++ 8.
Sorry for my confusion
Mark
Last modified: 1hr 10mins after originally posted --
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|