Marcus Comstedt (ACROSS) (Hail Ilpalazzo!) @ Pike (-) developers forum wrote:
object_index_no_free*() will add a reference for the item on the stack, so you need to free the svalue afterwards, which is conveniently done by pop_stack(). There is no difference between your two snippets; object_index_no_free*() adds a ref, so you need to subtract it when you're done.
So how do I do an efficient:
class A { array b; };
A c=A(); ... then from with the CMOD:
c->b+=({12});
I would like the += code to destructively expand array b, which would be possible if it had only one reference. But object_index_no_free adds a reference, you say. So how do I solve this?
I use this: push_int(12); f_aggregate(1); Pike_sp++; object_index_no_free2(Pike_sp-1, portal,0, MK_STRING_SVALUE("_datarows")); stack_swap(); f_add(2); object_set_index2(portal,0, MK_STRING_SVALUE("_datarows"), Pike_sp-1); Pike_sp--;
I realise that I need to run pop_stack() at the end instead, but that still leaves me puzzled about the efficient append.