1

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 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

This works:

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.