Hi, On 25 September 2014 09:06, Elefterios Stamatogiannakis <est...@gmail.com> wrote: > Unfortunately, the C library that i use (libsqlite3) does not provide a > function like that :( . It has a function that returns the size of the > string, but in my tests the overhead of doing another CFFI call (to find the > size) is greater than doing the 2nd copy (depending on the average string > size).
In general, if performance is an issue, particularly if you're running CPython (as opposed to PyPy), you can try to write small helpers in C that regroup a few operations. This can reduce the overhead of doing two calls instead of one. In this case, you can write this in the ffi.verify() part: size_t myGetString(xxx, char **presult) { *presult = getString(xxx); return strlen(*presult); } and then in Python you'd declare the function 'myGetString', and use it like that: p = ffi.new("char *[1]") # you can put this before some loop ... size = lib.myGetString(xxx, p) ..ffi.buffer(p[0], size).. A bientôt, Armin. _______________________________________________ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev