C,Python,ctypes退出代码-1073741819(0xC0000005)

C代码(DLL)

#include  #include  #include  struct Doc { wchar_t path[512]; int r; int g; int b; }; struct Docs { struct Doc docs[1000000]; }; struct Color { int r; int g; int b; }; float distance(int a, int b, int c, int d, int e, int f) { return sqrt((ab)*(ab)+(cd)*(cd)+(ef)*(ef)); } struct Doc main(long len, struct Color c, struct Docs ds) { long near = 1000000; long l; struct Doc f_d; for (l = 0; l < len; l++){ struct Doc d = ds.docs[l]; float dist = distance(cr, dr, cg, dg, cb, db); if (dist < near){ near = dist; f_d = d; } } return f_d; }; 

Python代码

 class Doc(ctypes.Structure): _fields_ = [("path", ctypes.c_wchar_p), ("r", ctypes.c_int), ("g", ctypes.c_int), ("b", ctypes.c_int)] class Docs(ctypes.Structure): _fields_ = [("docs", Doc * 1000000)] class Color(ctypes.Structure): _fields_ = [("r", ctypes.c_int), ("g", ctypes.c_int), ("b", ctypes.c_int)] structure = ctypes.CDLL('st.dll').main structure.restype = Doc structure.argstypes = (ctypes.c_long, Color(), Docs(),) 

从python调用main函数后,它以退出代码-1073741819删除。执行后执行返回"Process finished with exit code -1073741819 (0xC0000005)"
我认为这是因为内存分配或类似的东西。