取消引用已初始化为 list.begin() 的迭代器时出现段错误。
list<data>::iterator it;
for(int i=0; i< n; i++)
{
it = (list_empty[i]).begin();
while(it != (list_empty[i]).end())
{
cout<<"PROBLEM HERE: size="<<it->process.size<<endl;
//cout<<"log file i="<<i<<endl;
log_file_start(current_time, it,"list of empty");
it++;
}
}
这是来自 gdb 的错误:
Program received signal SIGSEGV, Segmentation fault.
[Switching to process 2888]
0x0804ecc0 in log_file_buddy (list_delay=..., list_vp=...,
list_empty=0x805a00c, method=..., current_time=0, n=10)
at fuctions_of_mm.cpp:425
425 cout<<"PROBLEM HERE: size="<<it->process.size << endl;
bt full 的 gdb 输出显示迭代器为 NULL。
(gdb) bt full
#0 0x0804ecc0 in log_file_buddy (list_delay=..., list_vp=...,
list_empty=0x805a00c, method=..., current_time=0, n=10)
at fuctions_of_mm.cpp:425
i = 8
it = {_M_node = 0x0}
out = <incomplete type>
尽管迭代器为 NULL,但仍会it != (list_empty[i]).end()
计算 。怎么了?
编辑:
抱歉遗漏。就是这样:list_empty = new list<data>[n];
N是给定的参数,表示:2^{N} = Size_of_Memory
编辑#2: 这是定义:
typedef struct data{
int position;
vp proccess;
int delay;
int current_life;
int time_start;
int time_stop;
int part_of_memory;
bool operator ==(const data& st)
{
return proccess.pid == st.proccess.pid;
}
}data;
以及vp的定义:
typedef struct {
int size;
int pid;//prosdiorisths diergasias
}vp
以及 n: 的值n = 10
。
list_empty 的声明是 list< data > *list_empty; .