std::vector 或其他一些允许迭代的动态容器是否可以部分驻留在 RAM 中并进行交换 (Linux)?
Can std::vector or some other dynamic container which allows iterating reside partially in RAM and swap (Linux)?
我有一个文本处理应用程序,它在代码中使用 std::vector
来存储大量数组、表格等。当我挖掘大量文本时,应用程序在遇到 RAM 边缘时崩溃,没有输入交换。
不幸的是,崩溃消息没有提供信息,它只是段错误。当然,使用调试器进行调查的可能性有很多,但是 不管 这种情况,我对 the explanation of how std::vector
works 中引起我注意的一件事感到好奇:
whenever you declare a vector object, it reserves some contiguous
space in memory. And if during an insertion, its exceeds that
capacity, it will create new space with a buffer in memory, copy the
data from the vector, insert the new data, and destroy older memory.
If your program is going to do lot of insertion and deletion, use
std::list.
可能是,当应用程序(我对 std::vector
特别感兴趣)请求创建一个超过 RAM 大小的连续对象时,即使在交换中有一个位置,它也会抛出错误?
我可以操作驻留在 RAM 中并与 std::list
或其他容器交换的动态数组吗?
谢谢大家,很抱歉提出菜鸟问题!那不是我的程序,我只是想让它工作,这个想法让我很好奇。所以看起来这只是一个巧合,当接近与我的 RAM 大小相等时它崩溃了。
Swap对程序操作是透明的。每当您的程序实际使用特定的内存页时,它将被带入主内存,但在任何其他时间 OS 可以自由地将其移动到交换区,您的程序将不会意识到这一事实。
段错误表示您正在尝试访问无效地址(无论是用于读取还是写入)。
我有一个文本处理应用程序,它在代码中使用 std::vector
来存储大量数组、表格等。当我挖掘大量文本时,应用程序在遇到 RAM 边缘时崩溃,没有输入交换。
不幸的是,崩溃消息没有提供信息,它只是段错误。当然,使用调试器进行调查的可能性有很多,但是 不管 这种情况,我对 the explanation of how std::vector
works 中引起我注意的一件事感到好奇:
whenever you declare a vector object, it reserves some contiguous space in memory. And if during an insertion, its exceeds that capacity, it will create new space with a buffer in memory, copy the data from the vector, insert the new data, and destroy older memory.
If your program is going to do lot of insertion and deletion, use std::list.
可能是,当应用程序(我对 std::vector
特别感兴趣)请求创建一个超过 RAM 大小的连续对象时,即使在交换中有一个位置,它也会抛出错误?
我可以操作驻留在 RAM 中并与 std::list
或其他容器交换的动态数组吗?
谢谢大家,很抱歉提出菜鸟问题!那不是我的程序,我只是想让它工作,这个想法让我很好奇。所以看起来这只是一个巧合,当接近与我的 RAM 大小相等时它崩溃了。
Swap对程序操作是透明的。每当您的程序实际使用特定的内存页时,它将被带入主内存,但在任何其他时间 OS 可以自由地将其移动到交换区,您的程序将不会意识到这一事实。
段错误表示您正在尝试访问无效地址(无论是用于读取还是写入)。