|
Soni wrote:
Could you find any solution?
No, do you have one?
Neville Franks, Author of ED for Windows. www.getsoft.com
Make money with our new Affilate program
|
|
|
|
|
Hi All,
I am new to COM and ATL and have written a short console app in an attempt to learn ATL's Database access techniques. My app creates an Accessor class, CDataSource object, CSession object and CCommand object. I am sucessfully able to get and display info from the database. The ATLDB objects are closed and CoUninitialized is called. Everything seems fine until COM is uninitialized. That is when I get the following error ... Unhandled exception in oleDB.exe: 0xC0000005 Access Violation. I am not sure what exception to catch or why it is happening. Like I said I am new to COM and ATL, maybe someone has a simple answer. If necessary I can post the code.
Thanks
Paul
|
|
|
|
|
Got it!!!
It's amazing what a couple of braces will do. By putting the COM objects in a block, the destructors are guaranteed to be called befor CoUninitilize().
|
|
|
|
|
I have a string array defined as std::vector<std::string> m_aData; in my class, which works fine and performs brilliantly, but when I have a fairly large number of elements (100,000) it takes an absolute age to remove the elements using m_aData.clear(); . It can literally take up to a minute to complete. I'm fairly new to STL, is there anything that can be done to improve the performance on this one line, or is there a different approach I can take to emptying the array?
Dylan
|
|
|
|
|
calling 100,000 ~std::string could take some time.
You can overwrite allocator for both string and vector to implement garbage collection of some kind, but it is very difficult.
|
|
|
|
|
How long are your strings? If your strings are long (i.e. 512 bytes), that would be 51 MB of data being deallocated. This can cause the paging system fits.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
I thought of this, and the strings are all 50 char's long, so that should be less the 5MB of memory.
I did a release build and checked the speed on that, and there was no real performance over head - is the speed problem just on the debug build? I ask cause each time I stop the running process in debug I find I end up in _free_dbg , which according to the comment in that file is the 'free a block in the debug heap'.
Can I safely assume that the performance overhead is only in debug mode? Like I said, pretty new to STL...
Dylan
|
|
|
|
|
Yes, this is a debug problem. The debug version of the allocation system will do checks of the allocation pools to make sure you haven't trash memory by overrunning allocated memory.
If it runs just fine in release mode, then don't worry about it.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
The std::string isn’t optimized. If you are developing under ATL or MFC use their string classes or create your own. When the string is deleted this may not affect speed but working other operations will improve alot.
|
|
|
|
|
wehn i am building an ATL DLL i am getting this error message "error MIDL2020 : error generating type library : SaveAllChanges Failed". What is the possible solutions;)
|
|
|
|
|
1. midl compiler has an option "/error all" I recommend trying it.
2. Check if your source control/target drive functioning properly
|
|
|
|
|
Hi, is there any code around to persist a vector etc. to/from the registry. I know I can write a simple iterator to do this, but I'm wondering if someone has written some generic code. The ability to persist to XML would also be most welcome.
I have looked around CP and did find "A set of template classes for working with the registry" http://www.codeproject.com/system/registry_value.asp[^] but that isn't quite what I need. Maybe I can just entend it!!
Neville Franks, Author of ED for Windows. www.getsoft.com
Make money with our new Affilate program
|
|
|
|
|
I program an app that uses a treeCtrl, and I use the tv_item::lParam save an address of an item in std::list. Code like this:
std::list<MyStruct> items;
....
std::list<MyStruct>::iterator pCur = items.begin();
TVM_INSERTITEM tvi;
tvi.item.mask = TVIF_TEXT | TVIF_PARAM...
tvi.item.lParam = &(*pCur);
....
TreeView_InsertItem(hTree, &tvi);
....
when I retrive an item of the tree and its MyStruct:
MyStruct* pMyStruct;
TV_ITEM item;
item.mask = TVIF_TEXT|TVIF_PARAM...
TreeView_GetItem(hTree, &item);
pMyStruct = (MyStruct*)item.lParam;
Now, the pMyStruct is not equal the &(*pCur) above.
How can I prohibit STL alter its items' addresses?
|
|
|
|
|
Well, std::list guarantees that addresses of their elements won't change (unless you delete them, of course). Do you mean that pMyStruct is not equal to the value tvi.item.lParam as it stood before calling TreeView_InsertItem ? If so, your problem lies elsewhere, and in fact does not have to do with std::list : basically, you're not getting the value you previously set in tvi.item.lParam .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
My problem is following.
I have a template MyTemplate
template <typename t="">
class MyTemplate
{
/////////////some members;
};
and I want to declare a vector whose elements would be of type MyTemplate.
It should be code like this (as I expect)
vector< MyTemplate<t> > MyVector;
But this of course does not compiled.
Where is my mistake?
Could anyone of gurus help me?
|
|
|
|
|
Visual C++ does not support templates as template parameters. Remember, template is not a type. You create a type from a template by providing template parameters.
|
|
|
|
|
template <typedef P>
class MyTemplate
{
public:
MyTemplate() {};
P m_Data;
};
typedef MyTemplate<int> MyIntTemplate;
std::vector<MyIntTemplate> MyIntTemplateVecotr;
Todd Smith
|
|
|
|
|
Just an FYI to everyone:
std::vector <MyTemplate<int> > MyIntTemplateVector;
Works just fine. The thing you have to watch out for is not including a space between the two >>.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Thank you Nemanja, thank you Todd, thank you Tim!
Of course I am familiar with answers proposed by Todd and Tim.
If I define a type of my template first, say
typedef MyTemplate<int> intMyTemplate;
and then define
typedef std::vector<intMyTemplate> intMyVector;
or even shorter
typedef std::vector< MyTemplate<int> > intMyVector;
all the rest will work fine.
But my goal is just to write some construction that would enable me
to define a vector in the fashion like this:
typedef MyVector<T> TMyVector;
and will produce an std::vector< MyTemplate<t> > which contains
elements of type of MyTemplate<t>.
I was trying to use something like this:
template<class T, template<class> class container=std::vector><br />
struct MyVector<br />
{<br />
container<T> m_container;<br />
};
but this code dosn't compile in VC60. Nemanja wrote that VC compiler
dosn't support template-templates. May be some service pack will help?
Or gurus could propose some other resolution?
Thank to all anyway!
|
|
|
|
|
Biochemist wrote:
template class container=std::vector>
struct MyVector
{
container m_container;
};
You're close, the problem is that there is no class called std::vector . std::vector is a template, not a class. You don't have a class until you create a specialization of std::vector , such as std::vector<int> .
So what I think you have in mind is:
template <typename ELEMENT, typename container = std::vector<ELEMENT> >
struct MyVector
{
container m_container;
};
--Mike--
I'm bored... Episode I bored.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Mike, what Biochemist wants is perfectly valid from the standard C++ point of view. It is called template template parameters , but it is not supported by VC++ 6.0 or 7.0. Microsoft promises that VC 7.1 will have them.
|
|
|
|
|
Nemanja Trifunovic wrote:
but it is not supported by VC++ 6.0 or 7.0.
I don't think that's entirely true, VC 7.0 does currently support template template parameters. The following compiles fine for me in VC 7.0:
template<
template<typename, typename> class Container = std::vector,
template<typename> class Allocator = std::allocator
>
struct number_holder {
Container<int, Allocator<int> > numbers_;
};<
cheers,
-B
|
|
|
|
|
Biochemist wrote:
Or gurus could propose some other resolution?
Not that I am a guru, but I think you could use good old macros to accomplish this.
Or wait for VC 7.1 to be released.
|
|
|
|
|
|