Optimizing repeated atom creation in the C interface

50 views
Skip to first unread message

Fermin Reig

unread,
May 8, 2012, 11:23:48 AM5/8/12
to personal...@googlegroups.com
Using the C interface, I create a mixed list that has a few repeated values (in this case nulls). This works fine:

knk(7,ks((S)sym),kf(nf),kf(nf),kf(nf),ki(ni),ki(ni),ki(ni))

I do this many times per second, and I'd prefer to create the atoms that repeat all the time only once, instead of fresh each time. (In the real code, there are non-nulls sometimes, but I wanted to keep the example simple.) We could do something like this:

K nullf = kf(nf);
K nulli = ki(ni);
...
knk(7,ks((S)sym),nullf, nullf, nullf, nulli, nulli, nulli)

I  know that I need to add calls to r1. The question is: do I need call r1 where I create the values with kf and ki, or at each use of the values inside the call to knk?

Thanks in advance
Fermín

Charles Skelton

unread,
May 8, 2012, 11:26:52 AM5/8/12
to personal...@googlegroups.com
each use

--
You received this message because you are subscribed to the Google Groups "Kdb+ Personal Developers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/personal-kdbplus/-/OqkiduYlNzgJ.
To post to this group, send email to personal...@googlegroups.com.
To unsubscribe from this group, send email to personal-kdbpl...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/personal-kdbplus?hl=en.

Fermin Reig

unread,
May 8, 2012, 12:23:08 PM5/8/12
to personal...@googlegroups.com
In hindsight, that's the only possible answer if you know how garbage collection by reference counting works. When you decrement the reference count of an object, you also decrement the count of anything referenced by it. In my example below with a mixed list, the list references each of the items inside the list. Therefore, if you insert the same item into multiple lists (or into multiple places in the same list), each time you insert it the ref count of the item has to be increased by one. 


On Tuesday, May 8, 2012 4:26:52 PM UTC+1, Charles Skelton wrote:
each use
Reply all
Reply to author
Forward
0 new messages