 |
|
 |
I am looking for a simple code in C++ to use in my program. Acually my program should run for a specific time (minutes or hours)and after this time finishes, the program should output the results.
Thanking you
|
|
|
|
 |
|
 |
Thanks for your debugbuf, it looks nice and clean except for one thing : Why did you overloaded xsputn ? I don't understand why you mess around with this method.
I didn't compile your code but lots of chances are if you comment out the function, it'll still work.
Greets.
|
|
|
|
 |
|
 |
Uh, oh, that was a long time ago...
Well, AFAIR I did so for performance and thread safety. Remember that CEditLog was intended to be used by multiple threads simultaneously that may render messages with a very high frequency. Therefore it is necessary that the streaming of a block of data (lets say a line) takes place quickly and uninterruptable, otherwise the output would be slow and messy, as messages from different threads get mixed up.
Both, efficiency and atomicity is ensured by the own xsputn() implementation, which protects the access to the shared buffer by a critical section and copies chunks of data blockwise instead of char by char. AFAIR.
--
Daniel Lohmann
http://www.losoft.de
(Hey, this page is worth looking! You can find some free and handy NT tools there )
|
|
|
|
 |
|
 |
Daniel is correct.
Without this apporach, the stream is not thread-safe. For some empirical proof, trying using the simpler stream object at http://www.codeproject.com/debug/debugout.asp.
Henry
|
|
|
|
 |
|
 |
#include <iostream> #include <algorithm> #include <time.h> #include <queue> #include <functional> using namespace std ; void Init(int& x) { x=rand()%1000; } void out(const int& x) { cout<<x<<" "; } void main() { srand(time(NULL)); int *A=new int[20]; for_each(&A[0],&A[20],Init); for_each(&A[0],&A[20],out); cout<<endl; priority_queue<int> x(&A[0],&A[20]); //I want to creat a Min heap,how can I do it in priority_queue? // priority_queue<int> x(&A[0],&A[20],greater<int>()); delete []A; for(int i=0;i<20;++i) { cout<<x.top()<<" "; x.pop(); } }
|
|
|
|
 |
|
 |
As we all know, #define's are secrets to debuggers, and therefore quite annoying.
The following will not confuse the debuggger:
#include
#include
#include
using namespace std;
typedef basic_ostream tostream;
#ifdef _UNICODE
tostream& tcout = wcout;
#else
tostream& tcout = cout;
#endif
int main(int argc, char* argv[])
{
tcout << _T("Test 123");
return 0;
}
Ben Berck
Semi-retired C++ guy
|
|
|
|
 |
|
 |
Sorry, didn't catch the angle bracket problem when pasting the code.
#include <tchar.h>
#include <iostream>
#include <ostream>
using namespace std;
typedef basic_ostream<TCHAR> tostream;
#ifdef _UNICODE
tostream& tcout = wcout;
#else
tostream& tcout = cout;
#endif
int main(int argc, char* argv[])
{
tcout << _T("Test 123");
return 0;
}
Ben Berck
Semi-retired C++ guy
|
|
|
|
 |
|
 |
Of course, if we're being picky, using namespace std is a colossally bad idea...
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
 |
|
 |
Christian Graus wrote:
Of course, if we're being picky, using namespace std is a colossally bad idea...
Of course.
--
Daniel Lohmann
http://www.losoft.de
|
|
|
|
 |
|
 |
In "~basic_dbgstreambuf()" the statement "delete psz;" should be "delete [] psz;" since "psz" was allocated with "new char_type[ BUF_SIZE ]" in "basic_dbgstreambuf()".
|
|
|
|
 |
|
 |
the "_stringf" function doesn't allocate exactly what it needs. Sure would be cool if the buffer size wasn't allocated via a const size.
MFCs CString::Format function is similar, but they parse the mask and variables to determine the length required for the string. Unfortunatley if any of the masks change for sprintf, it will break in addition to it not being protable.
I don't like either method, but don't offer a better solution. I am working on that.
|
|
|
|
 |
|
 |
It seems people like uses leading underscores in identifier names. Don't do this. The ISO C++ Standard specifically reserves names starting with an underscore to the compiler vender (see 17.4.3.1.2)
|
|
|
|
 |
|
 |
I think the author was simply following the Microsoft convention for their character string functions, like _tcscpy, _tcscmp, etc...
|
|
|
|
 |
|
 |
But Microsoft is allowed: They're the compiler vendor...
|
|
|
|
 |