|
Yes, the STL implementation that ships with VC++ 6.0 is hard to debug. You can switch to free STLPort (www.stlport.org), it's source is orders of magnitude more readable and even has debug diagnostics.
Anyway, if you'd like to stick with MFC containers, you create new template derived from CArray and make its copy constructor public.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Thanks for the tip. I think I will give STL a go. Have not touched it in about 5 years, but this gives me the excuse.
Giles
|
|
|
|
|
Following recomendations of some friends who says that standard C++ is more efficient and fast than non standard, I have a case that demonstrates it is not true....UNLESS I AM NOT CONSIDERING SOME OTHER C++ STANDARD FUNCTIONALITIES THAT ENCHANCE THE SPEED SUCH AS AN EFFICIENT BUFFERING.
The next program shows two ways of copying one file to another, the first one (CODE A) is very, very slow but the second (CODE B) is very fast. CODE A uses standard C++ (do not consider CTIME ), CODE B uses MFC.
Try this, copy/paste this program to your powerful computers and create a input text file of 40MB, run it and and you will see the amazing results.
By the way, I have necessity to read lines, that is why I show this case with this functionality.
Please comment me your points of view.
#include <afxwin.h>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void main()
{
// CODE A
// This code................
CTime startTime = CTime::GetCurrentTime();
string sReg;
ifstream entrada; entrada.open("prov.txt");
ofstream salida("prov1.txt");
while(getline(entrada, sReg))
salida << sReg << endl;
salida.close();
entrada.close();
CTime endTime = CTime::GetCurrentTime();
CTimeSpan ts = endTime - startTime;
cout << (LPCTSTR)ts.Format("Time consumed: Mins: %M, secs: %S" ) << endl;
// is extremely lower than ...
// CODE B
// this code......
startTime = CTime::GetCurrentTime();
CString stReg;
CStdioFile ent;
CStdioFile sal;
ent.Open("prov.txt", CFile::modeRead);
sal.Open("prov2.txt", CFile::modeCreate | CFile::modeReadWrite);
while (ent.ReadString(stReg)) {
sal.WriteString(stReg);
sal.WriteString("\n");
}
endTime = CTime::GetCurrentTime();
ts = endTime - startTime;
cout << (LPCTSTR)ts.Format("Time consumed: Mins: %M, secs: %S" ) << endl;
sal.Close();
ent.Close();
}
|
|
|
|
|
I beg your pardon . The #included files are:
afxwin.h, iostream, fstream and string.
For some reason, the angular brakets have some problems.
|
|
|
|
|
> For some reason, the angular brakets have some problems
I had similar problem yesterday too while posting a message. It looks like HTML was probbaly confusing with its tagging mechanism.
Later I figured if you provide a space after and before the brackets, it works fine. Here is how I did..
#include < afxtempl.h >
Get RadVC today! Play RAD in VC++
http://www.capitolsoft.com
|
|
|
|
|
Maybe you should check out how CStdioFile class actually does the copying of the file. This is how it does it, and it seems to me like it's using what your friend calls "standard C++". (With the exception of CString)
BOOL CStdioFile::ReadString(CString& rString)
{
ASSERT_VALID(this);
rString = &afxChNil;
const int nMaxSize = 128;
LPTSTR lpsz = rString.GetBuffer(nMaxSize);
LPTSTR lpszResult;
int nLen = 0;
for (;; )
{
lpszResult = _fgetts(lpsz, nMaxSize+1, m_pStream);
rString.ReleaseBuffer();
if (lpszResult == NULL && !feof(m_pStream))
{
clearerr(m_pStream);
AfxThrowFileException(CFileException::generic, _doserrno,
m_strFileName);
}
if (lpszResult == NULL ||
(nLen = lstrlen(lpsz)) < nMaxSize ||
lpsz[nLen-1] == '\n')
break;
nLen = rString.GetLength();
lpsz = rString.GetBuffer(nMaxSize + nLen) + nLen;
}
lpsz = rString.GetBuffer(0);
nLen = rString.GetLength();
if (nLen != 0 && lpsz[nLen-1] == '\n')
rString.GetBufferSetLength(nLen-1);
return lpszResult != NULL;
}
void CStdioFile::WriteString(LPCTSTR lpsz)
{
ASSERT(lpsz != NULL);
ASSERT(m_pStream != NULL);
if (_fputts(lpsz, m_pStream) == _TEOF)
AfxThrowFileException(CFileException::diskFull, _doserrno, m_strFileName);
}
Sprudling
|
|
|
|
|
Anybody who would make a blanket statement like that should just get a pat on the head and the response, "Oh, isn't that sweet".
Standard anything based on the lowest common denominator is usually slower than something designed for the platform in question. The important phrase being "is usually".
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
OK, I accept the title is really a good way to receive the pat and response "Oh, isn't that sweet". Sorry, I was referring to the libraries.
I only intended to recieve an answer such as: If you want to speed the "code A" using C++ standard libraries (not C and not MFC) use option1, option2, ...etc.
Actually, I need a very fast reading/writing process because I manage big files and I do not only read files, I make other complex memory manipulations for every line I read.
According to your answer, it means that the only solution is to use MFC, because I could demonstrate it is faster than C++ standard libraries. I do not feel happy because my intention to use standard C++ libraries for manipulating files (GUI is not important) will be deferred. May be, in a LINUX or UNIX environment it works faster but, in my work, we use Windows platform.
Thank you for your comments.
|
|
|
|
|
How to convert char * to LPWSTR for func. NetWkstaUserEnum??
|
|
|
|
|
Try MultiByteToWideChar function
regards
|
|
|
|
|
If you have ATL installed, take a look at AtlA2WHelper.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
If you're using MFC, you can use CString to do it, just call AllocSysString.
Either way, you can cast to _bstr_t in order to do this conversion. Just #include <comdef.h>
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
search for "String Conversion Macros" in MSDN
or locate in Visual C++/Reference/ATL/Reference
|
|
|
|
|
Hello,
I want to Know the Events that called, when i press the Close button from the Print Preview Button......
As if user presses both Print and Close button from the Print Preview window toolbar. the event that is called named
OnEndPrintPreview
and
OnEndPrinting
Actuallyu i want to differentiate both Events....
Thanks in Advance...
|
|
|
|
|
Hi,
I am facing a problem in Printing. That I have to make the pages of the data that i want to display in the form of the CStringList. Now when the Actual Printing Functions is called I check this by Using afxMessagebox that do textout the exactly string that i want to display and one more intertersting thing is that the print preview data is also diplaying but on the printer when I gave the print command neither from Print preview data is comming out on the printer page nor from Print method.
Can Any one help me...
|
|
|
|
|
I use the following statement to show the property of a file. But it does not work.
ShellExecute(AfxGetApp()->GetMainWnd()->m_hWnd,"properties","c:\\autoexec.bat",NULL,NULL,SW_SHOWDEFAULT);
How to resolve the trouble?
Thanks.
Maer
|
|
|
|
|
Try using ShellExecuteEx.
I didn't see properties listed for ShellExecute, but I did see it listed for ShellExecuteEx.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
Thanks again.
Can you give me a simple example to show how to invoke the "property" message box?
Best regards.
Maer
|
|
|
|
|
Try
ShellExecute(AfxGetMainWnd()->GetSafeHwnd(),"properties","c:\\autoexec.bat",NULL,NULL,SW_SHOWNORMAL);
|
|
|
|
|
Thank again.
I have tried your method, but it has no effect.
(I am using Win Me.)
Can you help?
Maer
|
|
|
|
|
Sirs,
I wanna download files from a given url and save them to disc by means of an MFC app.
Thanks to this great site the technical part is extremely easy.
However, before downloading it must be figured out which files are of interest.
One way is to check the first file for links and go after them. The other is to download all existing files from a given location, e.g. download all files from www.codeproject.com/internet/
Are there any tricks to figure out number and url of files of a given location?
Thanks for your help in advance.
Bunburry
A subject that is beautiful in itself gives no suggestion to the Artist. It lacks imperfection. (O.Wilde)
|
|
|
|
|
Even though I use MSLU, I have a special need for a FormatMessageW wrapper routine that will convent the parameter list from UNICODE to ASNI to allow FormatMessageA to be invoked.
Has anybody see this out there?
It wouldn't be that hard to write, but why reinvent the wheel.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
I am looking to create a sticky notes program for personal use. I am wondering if anyone has any leads or starts on how I can custom dialogs, kind of like Outlook Notes..... Anything would be great. Thank you.
|
|
|
|
|
Hey guys
I was wondering if anyone new how to add an extra menu on to the right click menu. What i mean is when you right click and put your cursor on the send to text it pops up another message well does anyone know how to do your own ones.
Cheers
Peter
|
|
|
|
|
Not sure if this is what you are asking for.
You want to add your own "Sent To" items for the file explorer?
To do that, just add normal shortcuts to the users profile directory tree in the "SentTo" folder. One of the SH folder routines should help you get the actual directory name for the current and all users.
On my system, the directory is:
"C:\Documents And Settings\Tim Smith\SendTo"
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|