This dll is passed an unmanaged class which contains vector<CDBRecord> m_vecRecords member variable. Within the managed C++ dll m_vecRecords is added to. This all works fine until our unmanaged C++ project attempts to m_vecRecords.clear() and I get an exception.
"Microsoft C++ exception: std::bad_alloc at memory location 0x0012ed68.."
and execution stops at
> msvcp90d.dll!std::allocator<char>::allocate(unsign ed int _Count=2315203557) Line 151 + 0xb bytes C++
Expand|Select|Wrap|Line Numbers
- void destroy(pointer _Ptr)
- { // destroy object at _Ptr
- _Destroy(_Ptr);
- }
Expand|Select|Wrap|Line Numbers
- pointer allocate(size_type _Count)
- { // allocate array of _Count elements
- return (_Allocate(_Count, (pointer)0));
- }
Expand|Select|Wrap|Line Numbers
- // IReadDatabase.h
- #pragma once
- #include "stdafx.h"
- #include <vector>
- #pragma unmanaged
- class StringPair
- {
- public:
- char *key; /* optional element of type xsd:string */
- char *value; /* optional element of type xsd:string */
- StringPair(); /* transient */
- };
- class CDBRecord
- {
- public:
- CDBRecord(long dbID = -1);
- StringPair *__ptr;
- int __size;
- };
- class CHitlist
- {
- public:
- CHitlist() {}
- long m_hit_total;
- std::vector<CDBRecord> m_vecRecords;
- };
- .....
- // ManagedDll.h
- #pragma once
- #include <IReadDatabase.h>
- #using <..\..\Shared Libraries\c#DLL.dll>
- using namespace System;
- using namespace System::Collections::Generic;
- using namespace c#DLL;
- #pragma managed
- namespace ManagedDll
- {
- bool CManagedDll::AddRecord(CHitlist* pHitlist)
- {
- CDBRecord rec;
- bool bRet = GetRecord(&rec);
- if (bRet)
- pHitlist->m_vecRecords.push_back(rec);
- return bRet;
- }