[Q] C-api: string|int|... construction

Fredrik Lundh fredrik at pythonware.com
Fri Apr 23 07:17:25 EDT 2004


Ames Andreas wrote:

> is it possible (within a C extension) to create a python string (or
> integer or other type) from an existing C string *without* copying the
> string?

*you* don't need to copy the string; if you create an object that needs
a copy, the type constructor will copy it for you.

you cannot create Python string objects that point to your own strings.

if you want to create a string-like object that points to your own C strings,
create your own type and implement the buffer interface.  see the "extending
and embedding" and "c api" documents for details.

(but note that unless you're talking about strings in the 100+ megabyte range,
or run on relatively old hardware, chances are that you're wasting your time.
modern computers can copy things really, really fast).

</F>







More information about the Python-list mailing list