Hi, On 23 September 2014 14:54, Eleytherios Stamatogiannakis <est...@gmail.com> wrote: >> p = clib.getString(...) # a "char *" >> length = clib.strlen(p) # the standard strlen() function from C >> b = unicode(ffi.buffer(p, length), 'utf-8') > > I've tried that, and the overhead of the second call is more or less equal > to the cost of the copy when using ffi.string.
You cannot have a C function returning a 'char[]'. That's why you need to declare it returning a 'char *', and then you don't know the length. Sorry, it's the way C works; there is nothing I can do about that :-) Occasionally, we see C functions with this kind of signature: size_t getString(xxx, char **result); This would return the length, and use 'result' as an output parameter, to store into '*result' a pointer to the string. If you really care about performance, then you might want to change the C library you're binding to in order to do that. A bientôt, Armin. _______________________________________________ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev