The reason for using "pimpl" is more to do with "binary compatibility" than with actually reducing compile/link time. The point is that the interface to the public portion stays the same whatever the implementation "behind the scenes" is. This means that there is no changes to the code using the outer interface, and thus an executable that uses the outer interface (that is, the client) doesn't need to be recompiled. It still needs to link, either statically or dynamically to the new "behind the scense" code.
Since the component "pimpl" is a pointer, it doesn't change size when the implementation changes. Consider for example that we have a container class specifically to store and retrieve C identifiers.
Trivial implementation:
Code:
class identifier
{
public:
void store(char *identifier, int id);
char *retrieve(int id);
private:
char **list;
int size;
...
}
If we now have a brilliant idea of storing the data in a different way [e.g. a binary tree, hash-table or some other "better" data format], then we would have to recompile ANY code that uses this class.
On the other hand, if we do this:
Code:
class identifier
{
public:
void store(char *identifier, int id);
char *retrieve(int id);
private:
_identifier *pimpl;
...
}
Now we can change the class "_identifier" as much as we like without affecting the code that only knows about identifier.
--
Mats