Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 映射清除抛出异常_C++_Visual C++_Dynamic Memory Allocation - Fatal编程技术网

C++ 映射清除抛出异常

C++ 映射清除抛出异常,c++,visual-c++,dynamic-memory-allocation,C++,Visual C++,Dynamic Memory Allocation,我有一个地图和流程来添加如下数据: interface CDBColumnInfo : public IDBColumnInfo { public: CDBColumnInfo(); ~CDBColumnInfo(); private: map<int,_bstr_t> m_rowIndexDataMap ; HRESULT AddDataToMap(){ _bstr_t record;

我有一个地图和流程来添加如下数据:

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;             
    }

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

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();

地图中的数据有什么问题?

您收到的错误:

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

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

堆检查频率宏

您可以指定C运行时库执行验证的频率 调试堆(_CrtCheckMemory)的大小,基于对 malloc、realloc、free和_msize


<更多信息见,< /p>哪个C++编译器?什么平台?<代码>接口< /代码>不是标准C++。这是微软那些奇怪的“增强”之一吗?也许你的库有缺陷。。。或者你在其他地方有内存损坏!好猎手!;)我们无法从代码中看出问题所在。我建议您不要将
\u bstr\u t
作为映射中的值,只存储“常规”字符串类型,例如
std::string
std::wstring
。仅将
\u bstr\u t
用作输入或输出,而不是映射值。您可能会导致程序中的其他地方出现堆损坏,并且在释放
\u bstr\u t
字符串时会出现堆损坏
File: minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp Line: 904

Expression: _CrtIsValidHeapPointer(block)