Hi,
I've been looking at the example in the cookbook (you'll find it by
searching for "Object Oriented Inline"). My interest is not so much in the
OO coding (which I avoid wherever possible), but in the memory management
aspect - specifically the automatic cleaning up of the blessed objects when
they go out of scope. Not having to specifically call cleanup routines is
really neat, imo - and it's something I've already put to good use.

The example in the cookbook deals with 'package soldier' and the C code
starts with:

            typedef struct {
                char* name;
                char* rank;
                long  serial;
            } Soldier;

That structure gets blessed into package soldier, and the DESTROY() function
looks like:

            void DESTROY(SV* obj) {
                Soldier* soldier = (Soldier*)SvIV(SvRV(obj));
                free(soldier->name);
                free(soldier->rank);
                free(soldier);
            }

But what if I have a second (different) structure that I wish to also bless
into 'package soldier', say:

            typedef struct {
                char* name;
                char* address;
                char* occupation;
                long  age;
            } Civilian;

The exisiting DESTROY() routine won't cope with having to clean up Civilian
structures. Is there a way that the DESTROY() routine can be modified so
that it can clean up both Civilian and Soldier structures ? ... or does the
Civilian structure need to be blessed into its own separate package - with
its own separate DESTROY() routine ?

Cheers,
Rob


Reply via email to