List Info

Thread: An (useless) Io Addon module




An (useless) Io Addon module
country flaguser name
Germany
2008-03-19 11:29:20

Well I have sit down and wrote an Addon for Io. Which in fact does not
much but handling a structure in C (not even all functions have been
wrapped) I just wonder if someone could have a look and bail out the
big faults.

I then would try to write some lines about how to write an Addon.

During that course I found some questions:
1) how does the normal C allocation play togehter with the GC from Io?

1.1)I have come up to the following "conclusion";
You do hand the C part separatly and you provide a Struct_fee function
in which you clean the parts which were allocated on the C side

1.2) If one keeps Io datastructures in the Struct_struct then you have
to write Struct_mark function

Is that a correct conclusion?

Here's some code I hope I wrote correctly
IoTestStruct *IoTestStruct_rawClone(IoTestStruct *proto)
{
IoObject *self = IoObject_rawClonePrimitive(proto);
IoObject_setDataPointer_(self, calloc(1, sizeof(IoTestStructData)));
/* test on NULL pointer ? */
DATA(self)->ts = newTestStruct(DATA(proto)->ts->dv,
DATA(proto)->ts->iv);
return self;
}

void IoTestStruct_free(IoTestStruct *self)
{
if (DATA(self)->ts) free(DATA(self)->ts);
free(IoObject_dataPointer(self));
}

In this part the free in the xxx_free function is needed because a
calloc is used above so it has to beclined. the othe free is the C
side which I introduced here:

IoTestStruct *IoTestStruct_rawClone(IoTestStruct *proto)
{
IoObject *self = IoObject_rawClonePrimitive(proto);
IoObject_setDataPointer_(self, calloc(1, sizeof(IoTestStructData)));
/* test on NULL pointer ? */
DATA(self)->ts = newTestStruct(DATA(proto)->ts->dv,
DATA(proto)->ts->iv);
return self;
}

and here:
IoTestStruct *IoTestStruct_proto(void *state)
{
IoObject *self = IoObject_new(state);
IoObject_tag_(self, IoTestStruct_newTag(state));

IoObject_setDataPointer_(self, calloc(1, sizeof(IoTestStructData)));
DATA(self)->ts = newTestStruct(0.0, 0);

Now what happens in the following case

foo := TestStruct clone

and not far later
foo := TestStruct clone

Is the memory proper released? What do I have to do to assure that?

I'm not fully sure about the complete initializaton objects also
so how to the xxxx_proto and xxx_newTag play togethter and what
function must I introdice in the xxx_newTag function?

I append a zip file with all the sources. I tried my luck on a Debian
64-bit box (unstable) and have used the latest Io I could git.

As written, comments, explanations etc are very welcome.

Regards
Friedrich

__._,_.___
.

__,_._,___
  
Re: An (useless) Io Addon module
country flaguser name
United States
2008-03-19 18:00:58


On 2008-03-19, at 9:29 AM, Friedrich Dominicus wrote:
>
> During that course I found some questions:
> 1) how does the normal C allocation play togehter with the GC from Io?
>
> 1.1)I have come up to the following "conclusion";
> You do hand the C part separatly and you provide a Struct_fee function
> in which you clean the parts which were allocated on the C side
>;
> 1.2) If one keeps Io datastructures in the Struct_struct then you have
>; to write Struct_mark function
>
>; Is that a correct conclusion?

Yes.

> Now what happens in the following case
>;
> foo := TestStruct clone
>
> and not far later
> foo := TestStruct clone
>
> Is the memory proper released? What do I have to do to assure that?

When the garbage collector gets around to it, yes. If you want to
force collection at a certain point, you can do:

Collector collect

But you should really only do this for debugging purposes as a forcing
a full (instead of incremental) collection can cause collection pauses
in running apps.

> I'm not fully sure about the complete initializaton objects also
>; so how to the xxxx_proto and xxx_newTag play togethter and what
>; function must I introdice in the xxx_newTag function?
>
> I append a zip file with all the sources. I tried my luck on a Debian
> 64-bit box (unstable) and have used the latest Io I could git.

I'll take a look when time permits.

- Steve

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )