Question about PyDict_SetItemString
stefan.behnel-n05pAM at web.de
Fri Jul 13 09:51:15 CEST 2007
> 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.
More information about the Python-list