Max Ivanov wrote: > I contsuct string inside function, how could I return it? > ---------- > 20 cdef char* close(self): > 21 return ''.join(self._data) > --------- > > If I copy it to temporary "p" as docs says, it wouldn't help I > suppose, because p will not be referenced by anyone. The only option > is to return python object? This is really a matter of working with C, and not so much a Cython question. A char* is just a pointer to some memory, and the question of managing that memory is an important question but will vary from occasion to occasion.
As what you are trying to do doesn't make so much sense one must have more context to give a better answer -- i.e. what are you trying to achieve overall, not only this snippet. I.e: 1) You want to use char* because it is feels "faster" than Python objects: No, you're better off with Python objects, char* is fundamentally something different. 2) The string is always a constant, but generated run-time: Assign it to a module global variable. 3) Something else: Perhaps allocate the memory manually and pass the target char* /in/ to the close func, and then write to it, rather than returning something... and so on. If you provide more details on why you want to do this perhaps we can give a better answer. Dag Sverre _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
