A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/090301.html below:

PyString_FromString and Binary Data

PyString_FromString and Binary Data PyString_FromString and Binary DataFredrik Lundh fredrik at pythonware.com
Sun Apr 29 15:30:28 EDT 2001
"gbgbgb at gmx.de" wrote:
> Is there any way to tell the PyString_FromString-Function not to
> truncate on ZEROs or is there some better way??

PyString_FromStringAndSize(buffer, size)

> Is it OK to free the buffer or does it Python for me??

in this case, it's your buffer, so you should free it.

> Is there a PyString_*-Function wich does not copy the input-string
> (buffer) to some other location but uses the input-pointer "in
> place"?? (The buffer gets copied and there is the memory wasted!)

Python cannot use arbitrary buffers to hold string data.  but in
many cases, you can create the string first:

    mystring = PyString_FromStringAndSize(NULL, size);
    if (!mystring)
        return NULL; /* out of memory */
    buffer = PyString_AS_STRING(mystring);
    /* load size bytes of data into buffer */
    return mystring;

Cheers /F



More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4