Aug 2, 2005

Network Setting Problem

There are two network connection profiles in my notebook.
One is for LAN, the other is for Hinet ADSL dial-up.
When the LAN profile has IP address and gateway address, I cannot use remote control by Hinet even ping and tracert.

Jun 11, 2005

How to use MySQL with named-pipe

When you link to MySQL, use a dot "." instead of localhost or IP at host name field.

Jun 5, 2005

HyperThreading

Today I went to library and read magazines. Dr.Dobb is an excellent magazine for programmers. An article describes something about single CPU, hyperthreading, and dual core.

  • Singel CPU has one CPU Status, one Interrupt Controller, and one ALU.
  • HyperThreading CPU has two CPU status, two Interrupt Controller, and one
    ALU.
  • Dual core CPU has two CPU status, two Interrupt Controller, and two
    ALU.
This solves my question. I have a program which calls MySQL a lot of times to calculate function values. But when I used two threads, two connections of MySQL, that program isn't getting faster as I expect. I guess the reason is that hyperthreading CPU has only one ALU, while one MySQL connection executing function calculation, the other must wait until ALU becomes available. They are not parallel runing and look like

Time 1 -> Time 2 -> Time 3 -> Time 4
connection1
receive SQL -> perform SQL -> return results -> receive SQL
connection2
receive SQL -> idle -> perform SQL -> return results

To obtain benefit of multithreading function calculation, dual core CPU and multi-CPU are really ways to do that.

Jun 1, 2005

MySQL, mysqlclient.lib, Visual C++, Windows XP

It's really hard to find related information of compiling programs with MySQL static library mysqlclient.lib. Fortunately, I got it!
There are two ways to link MySQL library, use libmysql.dll and mysqlclient.lib.

Use libmysql.dll:
Files libmysql.lib and libmysql.dll are at c:\program files\mysql\mysql server 4.1\lib\opt.
Just add libmysql.lib to your project. libmysql.lib is only a wrapper of libmysql.dll. Therefore, your program must run with libmysql.dll. The run-time library can be single thread version (/ML) or multi thread version.

Use mysqlclient.lib:
mysqlclient.lib is at same dictionary above. Add mysqlclient.lib to your project. If you build your project and get a lot of linker errors (LNK2001), you need to add some lib files to your project. Make sure that your project links wsock32.dll, advapi32.dll, and mysqlclient.lib. Open the propertity page of your project, click Linker options, click "input", click "other dependency", add .lib files as you need. You have to use multi-thread run-time library(/MT). The command line looks like
/OUT:"Release/LGP.exe" /INCREMENTAL:NO /NOLOGO /LIBPATH:"C:\Program
Files\MySQL\MySQL Server 4.1\lib\opt" /DEBUG /PDB:"Release/LGP.pdb"
/SUBSYSTEM:CONSOLE /OPT:REF /OPT:ICF /LTCG /MACHINE:X86 mysqlclient.lib wsock32.lib kernel32.lib
user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib
shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

If you open libmysql.dll at depends, the tool comes with Visual C++, you will see libmysql.dll depends on three DLLs: wsock32.dll, kernel32.dll, and advapi32.dll. That's why Mr. Armin Schoeffmann this web page:
http://www.issociate.de/board/post/182627/Linker_error_LNK2001_with_vc++6.0_and_mysqlclient.lib.html
suggests add advapi32.lib to LINK32_FLAGs. However, in my case, I lack of wsock32.lib not advapi32.lib.

If you are using Borland C++ Builder, you can use the utility IMPLIB to make your own libmysql.lib file, and use libmysql.dll to connect MySQL. Unfortunately, I don't know how to let BCB users use mysqlclient.lib.
If you have any question, please let me know.

Feb 21, 2005

BCB or VS2003?

Oh my god.
I spent so much time on compiling my project by MS Visual Studio .Net 2003!
I used BCB 6 before. And the project is done.
DDJ said that Intel C++ Compiler (ICC) is the fastest compiler. OK, but it must run with Visual C++ 6 or above!
NCTU bought the right of using so many MS products in school. Thus I have VS2003.
At first, it's cannot be compiled by VS2003! After a lot of settings are done, it's OK.
Then, it's cannot be compiled by ICC! A sucking fatal error : Internal error during pass 2.
Who knows what happened in its pass 2?
I found that the error may be caused by mspdb71.dll but I don't know why.
Thanks for the great help of MSDN. From the document, the mspdb71.dll seems only used in debug mode.
Change the configuration to Release, it's OK!!
But the built EXE file cannot run....orz....
I still have no idea. I DO NOT want to know why! ICC really sucks!

I feel that the help document of BCB6 is better than MSDN....
Some examples in MSDN are too complex, and,
there is no easy example about _beginthreadex().

It's a ....bad story....

Feb 1, 2005

Virtual destructor

Both constructor and copy constructor cannot be virtual. Destructor could better be virtual.
Consider two classes: Base and Derived:

class Base{

public:

Base(){cout<<"Base called."<

~Base(){ cout<<"Base deleted."<

}

class Derived:public Base{

public:

Derived(){ cout << "Derived called." <<>

~Derived() { cout << "Derived deleted." <<>

}


Now if we delete a Derived object, then we will get
Base called.
Derived called.
Base deleted.

The reason is that the Derived class uses the destructor of Base class. Therefore, we use the keyword "virtual" in front of the destructor of Base class: virtual ~Base(). We will get
Base called.
Derived called.
Derived deleted.
Base deleted.

Which is the correct result.
When a derived class has its own behavior in function foo() and foo() is existed in its base class without virtual, program will not execute foo() in derived class but in base class. If foo() is virtual, foo() of derived will be executed correctly.
Therefore, destructor should always be virtual, isn't it?