472,373 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,373 software developers and data experts.

Mixed managed\unmanaged dll causing problems with std::vector clear()

In order to use a C# dll from our unmanaged C++ project I have created a mixed managed\unmanaged c++ dll.
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
  1.     void destroy(pointer _Ptr)
  2.         {    // destroy object at _Ptr
  3.         _Destroy(_Ptr);
  4.         }
Expand|Select|Wrap|Line Numbers
  1.     pointer allocate(size_type _Count)
  2.         {    // allocate array of _Count elements
  3.         return (_Allocate(_Count, (pointer)0));
  4.         }
Here are some exerts of my code....I hope you can help!
Expand|Select|Wrap|Line Numbers
  1. // IReadDatabase.h
  2. #pragma once
  3. #include "stdafx.h"
  4. #include <vector>
  6. #pragma unmanaged
  8. class StringPair
  9. {
  10. public:
  11.     char *key;    /* optional element of type xsd:string */
  12.     char *value;    /* optional element of type xsd:string */
  13.     StringPair();    /* transient */
  14. };
  16. class CDBRecord
  17. {
  18. public:
  19.     CDBRecord(long dbID = -1);
  21.     StringPair *__ptr;
  22.     int __size;
  23. };
  25. class CHitlist
  26. {
  27. public:        
  28.     CHitlist() {}
  30.     long                m_hit_total;
  32.     std::vector<CDBRecord>   m_vecRecords;    
  33. };
  34. .....
  36. // ManagedDll.h
  38. #pragma once
  40. #include <IReadDatabase.h>
  42. #using <..\..\Shared Libraries\c#DLL.dll>
  43. using namespace System;
  44. using namespace System::Collections::Generic;
  45. using namespace c#DLL;
  47. #pragma managed
  49. namespace ManagedDll
  50. {        
  51.     bool CManagedDll::AddRecord(CHitlist* pHitlist)
  52.     {
  53.         CDBRecord rec;
  54.         bool bRet = GetRecord(&rec);
  56.         if (bRet)
  57.             pHitlist->m_vecRecords.push_back(rec);
  59.         return bRet;
  60.     }
Sep 16 '08 #1
0 1918

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Stefan Höhne | last post by:
Hi, as I recon, std::vector::clear()'s semantics changed from MS VC++ 6.0 to MS' DOT.NET - compiler. In the 6.0 version the capacity() of the vector did not change with the call to...
by: Jason Heyes | last post by:
To my understanding, std::vector does not use reference counting to avoid the overhead of copying and initialisation. Where can I get a reference counted implementation of std::vector? Thanks.
by: kayjean | last post by:
Hi. I have a small test.cc >> g++ -o test test.cc (gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) >> phase 1 (VSZ RSS 50844 47748 ) >> phase 2 (VSZ RSS 50844 47748 ) >> phase 3 (VSZ RSS...
by: canned.net | last post by:
I have a class Scene that has several subclasses: World, Vault, etc. I fill a vector with these classes and then cannot go through and delete them. What's the trick to deleting pointers from a...
by: lokchan | last post by:
i want to create a vector of pointer s.t. it can handle new and delete but also have std::vector interface can i implement by partial specialization and inherence like follow ? #include...
by: zl2k | last post by:
hi, all I need to use gsl_vector pointer with std::vector but not sure how to free the memory when I don't need it. Here is a piece of the code. =================== std::vector<gsl_vector *...
by: jubelbrus | last post by:
Hi I'm trying to do the following. #include <vector> #include <boost/thread/mutex.hpp> #include <boost/shared_ptr.hpp> #include <boost/tuple/tuple.hpp> class {
by: Bryan | last post by:
Hello all. I'm fairly new to c++. I've written several programs using std::vectors, and they've always worked just fine. Until today. The following is a snippet of my code (sorry, can't...
by: Daniel Pitts | last post by:
I have std::vector<Base *bases; I'd like to do something like: std::for_each(bases.begin(), bases.end(), operator delete); Is it possible without writing an adapter? Is there a better way? Is...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.