1. Need To Share Code

        In early 1990's C++ developers wanted to share code. We always want to reuse if something is already designed , developed and tested. But by then in C++ community the way to share the code was to share class libraries.

   For our example we will use a Fast String Search for example :

 faststring.h


class FastString {
      char *m_psz;
public:
FastString(const char *psz);
~FastString(void);
int Length(void) const; // returns # of characters
int Find(const char *psz) const; // returns offset
             } ;
faststring.cpp 
#include "faststring.h"
#include <string.h>
FastString::FastString(const char *psz)
m_psz(new char[strlen(psz) + 1J) {
strcpy(m_psz, psz);
}
FastString::~FastString(void) {
delete[J m_psz;
}
int FastString::Length(void) const {
return strlen(m_psz);
}
int FastString::Find(const char *psz) const {
// 0(1) lookup code deleted for clarity!
}
his often did not work. The following were the road blocks -  
  1. Developers often had to re-code significantly and the development effort was much higher.
  2. The whole application needed to be recompiled if the shared library was to be modified.
  3. Obviously at this stage we know why this approach is primitive.





    One more disadvantage which might be noting is that the application consuming the class library always created a separate object withing the application context. So for example a class FastString is shared among couple of applications , each application when started on the same client will use different spaces for the same class FastString. Hence, its an expensive waste of virtual memory.



No comments:

Post a Comment