This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [I don't think it's off-topic at all] Linking speed for C++


Hi,

On Thu, 31 May 2001, Fergus Henderson wrote:
> I haven't seen the code for KStaticDeleter, but I'll bet that it
> refers to a global or static member variable which contains the list of
> objects to be deleted.

One could think, so, yes.  But besides that -fPIC for the program didn't
help, this is also not the case, it just hold some normal class members,
the addition (and removing) to the global list is done through static
member functions of another class, and the private var which is changed
there (which indeed is static), isn't accessed from outside at all.  (As I
said, objdump revealed no R_386_COPY relocs besides RTTI and vtables).

This is KStaticDeleter without comments:
class KStaticDeleterBase {
public:
    virtual void destructObject() = 0;
};
template<class type> class KStaticDeleter : public KStaticDeleterBase {
public:
    KStaticDeleter() { deleteit = 0; }
    type *setObject( type *obj, bool isArray = false) {
        deleteit = obj;
        array = isArray;
        if (obj)
            KGlobal::registerStaticDeleter(this);
        else
            KGlobal::unregisterStaticDeleter(this);
        return obj;
    }
    virtual void destructObject() {
        if (array)
           delete [] deleteit;
        else
           delete deleteit;
        deleteit = 0;
    }
    virtual ~KStaticDeleter() {
        KGlobal::unregisterStaticDeleter(this);
        destructObject();
    }
private:
    type *deleteit;
    bool array;
};

This should be sane.  You can see it here, if interested:
http://webcvs.kde.org/cgi-bin/cvsweb.cgi/kdelibs/kdecore/kglobal.cpp?rev=1.59&content-type=text/x-cvsweb-markup

> For static members of template classes, things may get more complicated,
> especially if the template class is instantiated with the same type from
> two different shared object files.

This is something which I also thought about.  template with the same
params, but instatiated in different DSOs.  Hmm, -Bsymbolic shouldn't make
a difference, as long as no static data is involved in the template.


Ciao,
Michael.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]