简体   繁体   English

我的基于C的程序崩溃,分配了太多内存

[英]My C-based program is crashing, allocating too much memory

I'm reading a text file with coordinates and values and building an NxM table. 我正在读取包含坐标和值的文本文件,并构建一个NxM表。 The problem is that there is a 10^5 x 10^5 file, and I'm allocating space for this huge table. 问题是有一个10 ^ 5 x 10 ^ 5的文件,我正在为这个巨大的表分配空间。 The program won't run - it just stops. 该程序将无法运行-它将停止。 Is there any way more efficient to allocate this space, or save values in a different way? 有没有更有效的方式分配此空间或以其他方式保存值?

My program runs fine until the file is too big. 在文件太大之前,我的程序可以正常运行。

Use mmap Memory mapping and file I/O 使用mmap 内存映射和文件I / O

Anytime you are reading a binary file and not intending to extend it, mmap is almost always a better option. 每当您在读取二进制文件而不打算扩展它时,mmap几乎总是一个更好的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM