我现在使用cython读取输入文件,将字符串转换为int并将它们存储在ac数组(而不是列表)中以节省空间.我的代码看起来像这样:
cdef long p[10000000]
cdef long i
i = 0
f = open(filename, 'r')
for line in f:
temp = map(int, line.split())
p[i] = temp[0]
i = i + 1
f.close()
Run Code Online (Sandbox Code Playgroud)
但是,当我引用数组p时,程序总是被中止.不知何故,数组未被"定义",因为内存使用率非常低.但是,如果我正在做的话,它可以工作
cdef i
for i in range(0, 1000):
p[i] = i
Run Code Online (Sandbox Code Playgroud)