feelfree
feelfree

Reputation: 11753

The effect of number of functions in a C++ library

Suppose now two C++ libraries are available: one library has all the functions that will be needed by the program ( a C++ application program that will invoke the library), and the other one not only has the necessary functions that will be needed by the program but also has other functions that will not not used by the program. We assume that for the common functions in both libraries they are implemented in the same manner. My question is: when the program uses the library to perform a certain task, what's the effect of the library on the performance of the program?

The reason why I asked this question is because when developing a c++ library I often wrote some additional functions, which may not be invoked by the users of the library but are important for debugging. When the library is finished, I have two choices: one is to keep these auxiliary functions and the other is removing them or using other strategies of keep them (for example, define MACRO to disable these functions). If keeping these auxiliaries functions will not deteriorate the performance, I would like to keep them.

Upvotes: 1

Views: 102

Answers (2)

Manish
Manish

Reputation: 738

Well if you have written a static library that I guess you have. Then the only difference it will create is that the static library functionality will be part of you executable no matter if you use it or not.

I don't think it will hurt you in terms of speed but yes it will occupy a lot more space since a copy of lib will be created with you executable.

Upvotes: 1

Johan Råde
Johan Råde

Reputation: 21398

Everything else being the same, there will be no performance difference.

In addition, if the library is a static library, the linker will not include the functions that are not used, and the executables will have the same size.

Upvotes: 2

Related Questions