[Gambas-devel] Store GB_VARIANT in memory

Tobias Boege tobias at ...692...
Fri Aug 17 17:36:38 CEST 2012


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





More information about the Devel mailing list