kdb c++ interface: create byte list from std::string

688 views Asked by At

The following is very slow for long strings:

std::string s = "long string";
K klist = DBVec::CreateList(KG , s.length());
for (int i=0; i<s.length(); i++)
{
    kG(klist)[i]=s.c_str()[i];
}

It works acceptably fast (<100ms) for strings up to 100k, but slows to a crawl (tens of minutes, possibly hours) for strings of a few million characters. I don't see anything other than kG that can create nonlinearity. I don't see any reason for accessor function kG to be non-constant time, but there is just nothing else in this loop. Unfortunately I don't know how kG works due to lack of documentation.

Question: given a blob of binary data as std::string, what's the efficient way to construct a byte list?

2

There are 2 answers

0
user443854 On

This works:

memcpy(kG(klist), s.c_str(), s.length());

Still wonder why that loop is not O(N).

0
Aaron Davies On

kG is a macro defined in k.h which expands to ((x)->G0), i.e. follow the G0 pointer of the K object

http://kx.com/q/d/a/c.htm#Strings documents kp, which creates a K string object directly from a string, so presumably you could do K klist = kp(s.c_str()), which is probably faster