[Nasal] copying string data?
Jonatan Liljedahl
lijon at kymatica.com
Tue Nov 27 06:29:58 PST 2007
>> Also, I would like to get some clarification of the usage of
>> naTempSave(), do I understand it correctly that it prevents the naRef
>> from beeing garbage collected until any nasal code is run? Is it needed
>> in a case like this (pseudo-code):
>>
>> f_my_c_func() {
>> naRef x = create_something...
>> naRef v = naNewVector()
>> add x to v
>> }
>
> Yes, that's what it does. It protects the value from garbage
> collection in a temporary buffer in the context until the next time
> you use the context (at which point the C code is presumably done with
> it).
>
> But you don't need it there, because the naNew*() functions already
> save off the returned values in the same temporary array. You need it
> in situations where you are deleting a reference to the object (e.g.
> removing it from a vector) and need to do something (e.g. naNew*) that
> might cause a garbage collection before you add a new reference.
Ok, so all vectors and hashes (and strings?) I create in a C function
will be temp-saved until bytecode is run? But in the example above, x is
not in the vector v when naNewVector() is called, doesn't that mean that
x could be garbage collected (if it's something other than a object from
a naNew*() function)? But perhaps that's only numbers and they're not
garbage collectable?
--
/Jonatan - http://kymatica.com
More information about the Nasal
mailing list