On 3/31/08, Yukihiro Matsumoto <matz / ruby-lang.org> wrote:
> Hi,
>
> In message "Re: mark, alloc and free functions in C extensions"
> on Sun, 30 Mar 2008 20:12:38 +0900,
> "=?ISO-8859-1?Q?Gerardo_Santana_G=F3mez_Garrido?="
> <gerardo.santana / gmail.com> writes:
>
> |I have a class A written in C that contains a C structure. I have
> |defined the functions mark, alloc and free.
> |
> |I have another class B, written in C, that derives from class A and
> |adds another piece of C data.
> |
> |Should the class B define mark, alloc and free functions for both,
> |class A and class B, C structures?
> |
> |Or sould the class B care for its own C structure only? Will Ruby's
> |marking, allocation and liberation mechanism call their respective
> |functions?
>
> It's hard to say for sure without seeing your code, but basically your
> functions for class B should handle whole body of C structure (both A
> and B).

Thank you Matz.

Right now, I've coded both classes separately, thus duplicating code.
That's why it occurred to me to derive one from the other.

Most of the C structure is shared among both classes, except for one field.

This field, and another one that is common to both classes, are
pointers to database resources that must be allocated at
initialization and freed when the object is destroyed.

I wasn't sure that, for example, in the free function, I may free only
the derived class' database resource and expect that the free function
of the base class frees the other database resource and the structure
itself.

Or, that at initialization, I could expect that, after calling super,
the derived class can be confident that the C structure and the first
database resource were already allocated, and allocate the other
database resource.

--
Gerardo Santana