[Gambas-devel] Store GB_VARIANT in memory

Benoît Minisini gambas at ...1...
Fri Aug 17 17:48:27 CEST 2012


Le 17/08/2012 17:36, Tobias Boege a écrit :
> On Tue, 14 Aug 2012, Tobias Boege wrote:
>>> BEGIN_METHOD_VOID(Restore)
>>>
>>>     // The variant is copied in a temporary place.
>>>     GB.ReturnVariant(&THIS->tag);
>>>
>>>     // Free the stored variant.
>>>     // But you can't do it now, because the Variant will
>>>     // be referenced after the function has returned only.
>>>     // GB.StoreVariant(NULL, &THIS->tag);
>>>
>>> END_METHOD
>>>
>>> --8<-------------------------------------------------------
>>>
>>> Regards,
>>>
>>> --
>>> Beno?t Minisini
>>>
>>
>> _This_ is confusing and may be the error in my code. I thought, the Variant
>> is copied to a temporary place by GB.Return*() (AFAICS this "TEMP" variable.
>> Haven't I once heard that Gambas is not thread-safe? :-))
>> Why can't I free up my storage of the Variant?
>> Maybe my approach is just too different from what you proposed... What comes
>> to my mind now is this: GB.StoreVariant() refs the Object it takes but it
>> gets never unref'd by my code. If this is true, no wonder why I had memory
>> errors...
>>
>> I can (and actually wanted to) rewrite the code a bit so I can test your
>> suggestion - which is not to try to free the buffer but instead keep it and
>> re-use like the Array classes do. We'll see... Thanks.
>>
>> Regards,
>> Tobi
>
> OK, recalling the Socket class I apparently found a method to do this
> properly: I GB.Post() my destruction function. This works perfectly and is -
> I hope - correct.
>
> Commit coming soon.
>
> Regards,
> Tobi
>

That hack won't work if you don't have an event loop. And it's an 
horrible hack. :-)

What you need is something like what has been used in the implementation 
of the Array.Pop() method : that method returns something that must be 
freed.

That needs some new stuff in the interpreter API.

But at the moment I'm not sure how I will do that, so you must wait a 
little!

Regards,

-- 
Benoît Minisini




More information about the Devel mailing list