python - 如何将驻留在内存中的数据结构从一个模块传递到另一个模块

标签 python performance algorithm memory-management

我正在编写一个代码,其中我将一些文件存储到内存中的数据结构中,然后将在所有模块中使用该数据结构以访问该数据结构。 (节省时间)

由于代码是用 python 编写的,而且非常大,因此很难在函数之间传递该数据结构。

是否有任何可能的方法将文件到数据结构存储在代码的开头,然后我可以在任何模块中使用该数据结构,因为该数据结构在程序期间驻留在内存中执行。

请帮忙。非常重要..!!

我举个例子。

main.py ..... This is the start of the project, here I store the complete file-into-datastructure. other_module.py ..... This is some other module, where in i want to access that data structure which must be residing in the memory, as main.py is in execution and it had called other_module.py.

注意,我不能将文件到数据结构的东西存储在 other_module 中,因为那样会非常耗时,因为我在这里给出了一个非常小的例子,但实际上我正在处理一个更大的问题。

谢谢。

最佳答案

and is very big so its very hard to pass that data-structure from function-to-function.

不,不是。 Python 变量不是那样工作的。您隐含地获得了一个指针。

关于python - 如何将驻留在内存中的数据结构从一个模块传递到另一个模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10100399/

相关文章:

python - 如何使用 MySQL executemany 更新 Python 中的列表列表?

python - 使用 tkinter 不可关闭的窗口

python - 如何使用 groupby 减去列中的值

python - 数据框分层索引加速

algorithm - 如何提高CUDA中needleman-wunsch算法的性能

c# - 如果 IEnumerable 具有单个元素,如何有效地检查?

performance - 使用 ssd 和 mmap 改进并发文件读取

performance - MATLAB性能基准测试

回溯变量的使用和依赖关系的算法

string - KMP算法与Z算法的关系