Question about PyDict_SetItemString

Stefan Behnel stefan.behnel-n05pAM at web.de
Fri Jul 13 03:51:15 EDT 2007


lgx schrieb:
> Does PyDict_SetItemString(pDict,"key",PyString_FromString("value"))
> cause memory leak?

You shouldn't use that at all. If you look at the sources, what SetItemString
does is: create a Python string from the char* and call PyDict_SetItem() to
put the new string in. So it is actually much more efficient to use
PyDict_SetItem() directly in your case.

If you want to temporarily create a char* from a string and you know that the
char content won't be modified, use the PyString_FROM_STRING macro, which just
returns the internal pointer.

Stefan



More information about the Python-list mailing list