473,385 Members | 1,168 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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.         }
then
Expand|Select|Wrap|Line Numbers
  1.     pointer allocate(size_type _Count)
  2.         {    // allocate array of _Count elements
  3.         return (_Allocate(_Count, (pointer)0));
  4.         }
  5.  
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>
  5.  
  6. #pragma unmanaged
  7.  
  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. };
  15.  
  16. class CDBRecord
  17. {
  18. public:
  19.     CDBRecord(long dbID = -1);
  20.  
  21.     StringPair *__ptr;
  22.     int __size;
  23. };
  24.  
  25. class CHitlist
  26. {
  27. public:        
  28.     CHitlist() {}
  29.  
  30.     long                m_hit_total;
  31.  
  32.     std::vector<CDBRecord>   m_vecRecords;    
  33. };
  34. .....
  35.  
  36. // ManagedDll.h
  37.  
  38. #pragma once
  39.  
  40. #include <IReadDatabase.h>
  41.  
  42. #using <..\..\Shared Libraries\c#DLL.dll>
  43. using namespace System;
  44. using namespace System::Collections::Generic;
  45. using namespace c#DLL;
  46.  
  47. #pragma managed
  48.  
  49. namespace ManagedDll
  50. {        
  51.     bool CManagedDll::AddRecord(CHitlist* pHitlist)
  52.     {
  53.         CDBRecord rec;
  54.         bool bRet = GetRecord(&rec);
  55.  
  56.         if (bRet)
  57.             pHitlist->m_vecRecords.push_back(rec);
  58.  
  59.         return bRet;
  60.     }
....
Sep 16 '08 #1
0 1972

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

Similar topics

10
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...
27
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.
3
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...
5
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...
6
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...
2
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 *...
13
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 {
8
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...
19
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.