gpt4 book ai didi

c++ - 映射清除抛出异常

转载 作者:行者123 更新时间:2023-11-30 04:47:45 24 4
gpt4 key购买 nike

我有一个 map 和过程来添加这样的数据:

interface CDBColumnInfo
: public IDBColumnInfo
{
public:
CDBColumnInfo();
~CDBColumnInfo();
private:
map<int,_bstr_t> m_rowIndexDataMap ;

HRESULT AddDataToMap(){
_bstr_t record;
for (int rownum = 0; rownum < num_rows; ++rownum){
const int num_cols = PQnfields(res);
record = "";
for (int colnum = 0; colnum < num_cols; ++colnum) {
if (PQgetisnull(res, rownum, colnum) == 0) {
_bstr_t data = PQgetvalue(res, rownum, colnum);
record = record + data;
}
else {
record = record + "<NULL>";
}

if (colnum + 1 < num_cols) {
record = record + "#";
}
}
m_rowIndexDataMap[rownum] = record;
}

}

程序完成后,我通过以下方式清除析构函数中的映射:

CDBColumnInfo::~CDBColumnInfo() {
m_rowIndexDataMap.clear();
}

析构函数完成时出现异常:

File: minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp
Line: 904

Expression: _CrtIsValidHeapPointer(block)

我尝试循环映射并手动确定第一个元素中发生的异常:

for (auto it = m_rowIndexDataMap.cbegin(); it != m_rowIndexDataMap.cend() ;)
{

it = m_rowIndexDataMap.erase(it); // exception happened at first element

}
m_rowIndexDataMap.clear();

map 中的数据有什么问题?

最佳答案

您收到的错误:

File: minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp Line: 904

Expression: _CrtIsValidHeapPointer(block)

不一定是由“实际”代码或调用堆栈引起的,但很可能是由代码中的其他地方引起的,因为它可能是由堆的例行检查引起的:

Heap-Check Frequency Macros

You can specify how often the C run-time library performs validation of the debug heap (_CrtCheckMemory) based on the number of calls to malloc, realloc, free, and _msize.

有关详细信息,请参阅 _CrtSetDbgFlag

关于c++ - 映射清除抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56108065/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com