[英]Slowdown and high memory uasge when adding a new module in embedded Python 3.4 on 64bit Windows
我需要讓我的Python程序訪問我的C函數。 因此,我使用文檔中的示例開始使用。
不幸的是,它非常慢,占用了我的全部內存。
我正在使用Windows 7 64位,Python 3.4和gcc(rubenvb-4.8.0)4.8.0。
為了完整起見,下面是文檔中的代碼:
#include <Python.h>
static int numargs=0;
static PyObject*
emb_numargs(PyObject *self, PyObject *args)
{
if(!PyArg_ParseTuple(args, ":numargs"))
return NULL;
return PyLong_FromLong(numargs);
}
static PyMethodDef EmbMethods[] = {
{"numargs", emb_numargs, METH_VARARGS,
"Return the number of arguments received by the process."},
{NULL, NULL, 0, NULL}
};
static PyModuleDef EmbModule = {
PyModuleDef_HEAD_INIT, "emb", NULL, -1, EmbMethods,
NULL, NULL, NULL, NULL
};
static PyObject*
PyInit_emb(void)
{
return PyModule_Create(&EmbModule);
}
int main()
{
[...]
numargs = argc;
PyImport_AppendInittab("emb", &PyInit_emb);
Py_Initialize();
pModule = PyImport_Import(pName);
[...]
}
python程序具有以下代碼:
import emb
print("Number of arguments", emb.numargs())
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.