fixed a problem with gddDestructor and reference counting

This commit is contained in:
Jim Kowalkowski
1997-03-17 17:14:48 +00:00
parent b95f7afd3c
commit 4c99a53852
2 changed files with 23 additions and 1 deletions

View File

@@ -4,6 +4,9 @@
// $Id$
//
// $Log$
// Revision 1.18 1997/01/21 15:13:06 jbk
// free up resources in clearData
//
// Revision 1.17 1997/01/12 20:32:45 jbk
// many errors fixed
//
@@ -304,6 +307,7 @@ gddStatus gdd::registerDestructor(gddDestructor* dest)
gddStatus gdd::replaceDestructor(gddDestructor* dest)
{
destruct=dest;
destruct->reference();
if(isContainer()||isFlat())
markManaged();
@@ -333,6 +337,7 @@ gddStatus gdd::genCopy(aitEnum t, const void* d)
{
setData(buf);
destruct=new gddDestructor;
destruct->reference();
aitConvert(primitiveType(),dataPointer(),t,d,
getDataSizeElements());
}
@@ -451,6 +456,7 @@ gddStatus gdd::copyStuff(gdd* dd,int ctype)
if(array=new aitUint8[a_size])
{
destruct=new gddDestructor;
destruct->reference();
memcpy(array,dd->dataPointer(),a_size);
setData(array);
}
@@ -843,6 +849,7 @@ int gdd::flattenDDs(gddContainer* dd, void* buf, size_t size)
{
ptr[i].setData(NULL);
ptr[i].destruct=new gddContainerCleaner(&ptr[i]);
ptr[i].destruct->reference();
}
}
}
@@ -1353,6 +1360,7 @@ gddStatus gdd::put(const gdd* dd)
if((arr=new aitUint8[sz]))
{
destruct=new gddDestructor;
destruct->reference();
setData(arr);
}
else

View File

@@ -8,6 +8,9 @@
* $Id$
*
* $Log$
* Revision 1.20 1997/01/12 20:32:46 jbk
* many errors fixed
*
* Revision 1.18 1996/11/04 17:12:50 jbk
* fix setFirst
*
@@ -242,6 +245,17 @@ inline gddBounds* gddBounds3D::boundArray(void) { return (gddBounds*)b; }
// function run(void*). The default behavior will be to treat the void*
// data as an array of aitInt8 and call remove.
// **** WARNING!
// The reference count is initialized to zero. This means that if you
// create one and want to keep it, you must reference it twice - the
// initial time and a time for your personal use. This is because the
// gdd library automatically increments the reference count on
// destructors when data is referenced into a gdd with a destructor.
// Remember the rule: if you pass a destructor to someone, then that
// someone now owns the destructor. A reference count of 1 indicates that
// the thing will go away when unreferenced - which is what you will
// have if you only reference the destructor once after it is created.
class gddDestructor
{
public:
@@ -262,7 +276,7 @@ private:
gdd_NEWDEL_DATA(gddDestructor)
};
inline gddDestructor::gddDestructor(void) { ref_cnt=1; arg=NULL; }
inline gddDestructor::gddDestructor(void) { ref_cnt=0; arg=NULL; }
inline gddDestructor::gddDestructor(void* usr_arg) { ref_cnt=1; arg=usr_arg; }
inline void gddDestructor::reference(void) { ref_cnt++; }
inline int gddDestructor::refCount(void) const { return ref_cnt; }