1

当我尝试将一对添加到向量时,我收到此错误:

table: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.
Aborted

这是方法:

std::vector<std::pair <int, int> > AI::genPosNormal(int p, int dice)
{
  std::vector<std::pair <int, int> > pos;
  std::pair<int, int> step;

  for(int i = p; i < 25-dice; i++){
    if(board[BLACK][i] > 0 && board[WHITE][i+dice] < 2){
      step.first = i;
      step.second = dice;
      pos.push_back(step);
    }
  }
  return pos;
}
4

1 回答 1

1

有点晚了。但我发现在 std::pair 的 std::vector 中使用 .reserve() 可以解决问题。我仍然必须弄清楚为什么会导致错误,但似乎在 stl_uninitialized.h 中会引发错误标志。

于 2014-06-26T19:36:52.177 回答