|
berndg wrote:
Since it is your process that actually creates those threads, wouldn't you be the best person to know whether or how many threads are in use?
It seems a bit hard expecting Microsoft to predict your source code.
I want to compile the whole program (my own code + MS code) either in 'single-threaded' or 'multi-threaded' mode. Depending on the threading-mode I want to call different functions. This should be done with macros (what else).
To make it work I need a #define similar to
#define _POSIX_THREADS
Yes, I can #define my own macro, but that's not the point.
What am I missing?
|
|
|
|
|
|
I know ...
From MSDN: C/C++ Preprocessor Reference : Predefined Macros
See Also Macros | Preprocessor Operators | Preprocessor Directives
The compiler recognizes 10 predefined ANSI C macros, and the Microsoft C++ implementation provides several more. These macros take no arguments and cannot be redefined. Their value, except for __LINE__ and __FILE__, must be constant throughout compilation. Some of the predefined macros listed below are defined with multiple values.
_MT Defined when /MD or /MDd (Multithreaded DLL) or /MT or /MTd (Multithreaded) is specified.
|
|
|
|
|
Blake Miller wrote:
_MT Defined when /MD or /MDd (Multithreaded DLL) or /MT or /MTd (Multithreaded) is specified.
Bingo! Thank you very much!
|
|
|
|
|
If you use this kind of macro magic just to implement your synchronization, this is bad! It is better to define a helper class that implements your lock, and define a macro that creates the lock or does nothing depending on the _MT switch.
Example:
class CSemaphoreLock
{
public:
CSemaphoreLock(HANDLE hSem) : m_hSem(hSem) { ::WaitForSingleObject(hSem, INFINITE); }
~CSemaphoreLock() { ::ReleaseSemaphore(m_hSem, 1, NULL); }
private:
const HANDLE m_hSem;
};
#ifdef _MT
# define SEMAPHORE_LOCK(HSEM) CSemaphoreLock TempLock_(HSEM)
#else
# define SEMAPHORE_LOCK(HSEM)
#endif // _MT
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Yes there is:
/MT Defines _MT so that multithread-specific versions of the run-time routines are selected from the standard header (.h) files. This option also causes the compiler to place the library name LIBCMT.lib into the .obj file so that the linker will use LIBCMT.lib to resolve external symbols. Either /MT or /MD (or their debug equivalents /MTd or /MDd) is required to create multithreaded programs. <br />
/MTd Defines _DEBUG and _MT. Defining _MT causes multithread-specific versions of the run-time routines to be selected from the standard .h files. This option also causes the compiler to place the library name LIBCMTD.lib into the .obj file so that the linker will use LIBCMTD.lib to resolve external symbols. Either /MTd or /MDd (or their non-debug equivalents /MT or MD) is required to create multithreaded programs.
Don't try it, just do it!
|
|
|
|
|
can anybody show me which tool can generate my code from VC to API document spec like javadoc from Sun
|
|
|
|
|
|
doxygen[^] + graphviz[^] is a good solution. It also permits to use java doc style.
Marc Soleda
... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
|
|
|
|
|
|
how about the other tools like RationalRose or Together, i have tried with Doxygen but it is limited with class diagram showing that only detect inheritance relations, how about other relations like Association,Aggregation, ....
i would like to find a tool that not only support feature to generate API doc spec like Doxygen but also can generate class diagram as RationalRose.
|
|
|
|
|
Would anybody tell me what is virtual destructor?
|
|
|
|
|
Hi
if u have for example multiple inherited classes
and u need to to call the destructor for one of them
so virtual used to call ur specific function u want
and virtual destructor always used at the frmae and application class for document and view
MFC programmer
|
|
|
|
|
the virtual C++ keywowrd tells that a member function is called instead of the base class' one.
for example, let's see this case :
<font color=blue>class</font> CBaseClass {
<font color=blue>public</font>:
<font color=blue>void</font> print() {
printf(<font color=gray>"CBaseClass\n"</font>);
}
};
<font color=blue>class</font> A : <font color=blue>public</font> CBaseClass {
<font color=blue>public</font>:
<font color=blue>void</font> print() {
printf(<font color=gray>"A\n"</font>);
}
};
now, if you make this :
CBaseClass* p = <font color=blue>new</font> A();
p->print();
this will display CBaseClass .
now, imagine you would like to access A::print() through a pointer to the base class, here come virtual .
if we had coded this instead :
<font color=blue>virtual void</font> print() { <font color=green></font> }
this would call the 'correct' print() function (as p is assigned with a A object, p->print() will call A::print() , even if p is a CBaseClass pointer).
understand better now ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
|
Per MSDN:
A destructor implemented by declaring a base class's destructor with the keyword virtual. A virtual destructor ensures that, when delete is applied to a base class pointer or reference, it calls the destructor implemented in the derived class, if an implementation exists.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
What complicated descriptions .
If class A is derived from class B, and you create class A, cast it to a B pointer and delete the B pointer.
If there is no virtual destructor, only the B destructor will be called.
Don't try it, just do it!
|
|
|
|
|
Back in the old days when I used to use VS6, there was a profiler extension that allowed us to produce code timing and coverage for our C++ programs. Now I've been told that this feature have been removed for VS7.1
What do you guys use (if any) to get similar optimisation reports now in VS7.1 ? I do not use the .NET framework.
I Dream of Absolute Zero
|
|
|
|
|
|
Sweet. I'll test it out on a few of my projects.
I Dream of Absolute Zero
|
|
|
|
|
Not used it, but I think there is a bit of a profiler beast in VS 2005 for C++. You can probably play with the Beta. By the sounds of things the compiler itself can use the profiler results to add its own extra optimisations to the code based off the results.
Either a case of waiting until November, or using the Beta now.
"Je pense, donc je mange." - Rene Descartes 1689 - Just before his mother put his tea on the table.
Shameless Plug - Distributed Database Transactions in .NET using COM+
|
|
|
|
|
I use Ado to connect SQL Server,when I deleted a record,the Provider report a Error Message:"Row handle referred to a deleted row or a row marked for deletion".
The following is my sample code:
pRecordset->delete(adAffectCurrent);
pRecordset->Update();
pRecordset->MoveFirst();
i=0;
while(!m_pRecordset->adoEOF)
{
varValue = pRecordset->GetCollect(long(i);
i++;
if (varValue.vt == VT_NULL)
bstrValue = "";
AfxMessageBox(bstrValue);
pRecordset->MoveNext();
}
|
|
|
|
|
This could be many things. Some people get it because they lack a primary key. Others because they are using a JOIN in their select and find they must set the UniqueTable and ResyncCommand and call Resync after a method. Others must call Refresh(). Others get it working using the SQL Command equivalents. This is just what I heard from groups.google.com, I don't use ADO.
|
|
|
|
|
I'm writing an application with Visual C++ that needs to use Window's task scheduler to launch another application at some time in the future.
My problem is that whilst I can create a task that is supposed to run in the future, the Next Run Time (when viewed through Control Panel->Scheduled Tasks) is always "Never".
I've found that if I open the task through Control Panel->Scheduled Tasks and then delete the last character of the 'Run' string and enter the character again (just so it flags the file as having changes made) then click OK, the "Next Run Time" field then has the correct date and time.
It seems that although I've been able to create the task as I need it, it needs to be 'enabled' somehow - something that happens when I save from the Windows GUI but not when its done through my code.
I've been using the example code on MSDN as a guide, however I haven't been able to find any differences that could indicate where I'm going wrong.
Does anyone have any ideas as to what I'm doing wrong?
My OS is Windows XP Professional with SP2 if thats significant.
Thanks,
Brian.
|
|
|
|
|