|
Hi Mark,
Yes I was also expecting that if method 1 worked method 3 would too. I will check the two articles you send me and I'll let you know if they help me thanks for your help.
|
|
|
|
|
Greetings,
Let's say I do this:
vector<cmyclass *=""> m_vMyVector;
void SomeFunction(CString strID, bool bStatus)
{
CMyClass * pMyObj = new CMyClass(strID, bStatus);
m_vMyVector.push_back(pMyObj);
pMyObj = NULL;
}
Let's say SomeFunction(...) is in a loop and I create several of these objects. When I call m_vMyVector.clear() will there be a memory leak? In essence, I want to know if I have to go back and call delete on each of the elements in m_vMyVector or will the memory be freed once I call the vector's "clear" method or once the vector is destroyed when the class containing it is destroyed. Also, once I add pMyObj to the vector and reassign the one in the function to point to null, the vector still retains its own valid pointers to the objects in memory, correct?
Thanks for any help or insight you can provide.
Sincerely,
BP
|
|
|
|
|
You will need to loop the vector to delete each item individually, unless you are using auto_ptr thingies.
it = m_vMyVetor.begin();
while (it!= m_vMyVector.end() )
{
delete *it;
++it;
}
m_vMyVector.clear();
and you are correct about the second thing, IMO, assign it back to NULL is not necessary, but a nice touch.
|
|
|
|
|
Thanks,
I appreciate your response.
BP
|
|
|
|
|
Hi,
It's not safe to use auto_ptr in a standard container (reference: see e.g. here[^], here[^]
But generally, smart pointers is the way to go. (only auto_ptr is a troubled implementation)
I've written an article about the smart pointer library included with boost - Clickety[^]. That might give you some ideas.
Developers, Developers, Developers, Developers, Developers, Developers, Velopers, Develprs, Developers! We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP Linkify!|Fold With Us!
|
|
|
|
|
Maximilien wrote: auto_pt
do me a favor, never use auto_ptr
Developers, Developers, Developers, Developers, Developers, Developers, Velopers, Develprs, Developers! We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP Linkify!|Fold With Us!
|
|
|
|
|
Thanks PeterChen,
I have heard a lot of great things about boost. Being new to programming, it seems a bit intimidating to use and I am admittedly frightened at the prospect of including it then having to deal with Visual Studio 2003 not playing nice with it. Is boost easy to use?
At any rate, I'll check out your article.
Peace,
BP
|
|
|
|
|
boost can certainly be intimidating. It is a collection of many different libraries, and some of them are clearly made for advanced program(mer)s.
The smart pointers are an exception. They are (IMO) a very important concept, maybe the first step away from beginner towards advanced programming. They should be easy to understand if you have mastered basic memory management and RAII (using constructors and destructors to acquire and release resources like memory, file handles, ...). I also tried to make the article suitable for beginners (if you read it, please tell me if it works for you )
I've been using them with VC6 and VC8, so VC2003 should be no problem. But if boost is still to intimidating, there are many other smart pointer implementations. I recommend boost because they are well designed, flexible, but still fairly simple (a good balance).
Developers, Developers, Developers, Developers, Developers, Developers, Velopers, Develprs, Developers! We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP Linkify!|Fold With Us!
|
|
|
|
|
sorry, I thought that would be usefull.
thanks for the heads up.
|
|
|
|
|
How do I split doc into pages for printing? I have a long multiline string that I want to print. How do I calc number of pages needed to print it? How do I call OnDraw for specific page?
An example would be great.
|
|
|
|
|
Hello all.Any body know how i can create toolbaar in my application??
Please if possible then send me code..
Thank you very much..
Shah Satish..
|
|
|
|
|
|
|
How can I programmatically change setting in Local Area Connection property using C++ application?
I need to uncheck some property and then check it back. For example File and Printer Sharing for Microsoft Networks.
Thank you.
Ilya
-- modified at 16:03 Wednesday 20th December, 2006
|
|
|
|
|
If you getting error like that
error C2872: 'IXMLDOMParseErrorPtr' : ambiguous symbol
could be 'c:\program files\microsoft visual studio 8\vc\include\comdefsp.h(1263) : _com_ptr_t<_IIID> IXMLDOMParseErrorPtr'
1> with
1> [
1> _IIID=_com_IIID<ixmldomparseerror,& _guid_3efaa426_272f_11d2_836f_0000f87a7782="">
1> ]
1> or '.\debug\msxml3.tlh(250) : MSXML2::IXMLDOMParseErrorPtr'
What would be correct resolution
1. instead of
IXMLDOMParseErrorPtr spErr = pXMLDom->parseError;
use
::IXMLDOMParseErrorPtr spErr = pXMLDom->parseError;
Or use
MSXML2::IXMLDOMParseErrorPtr spErr = pXMLDom->parseError;
|
|
|
|
|
|
i don't know if it's your case, but it's commonly bad practice to use a using namespace directive, because of such problems of ambiguousness...
|
|
|
|
|
I know, man I know. It was too many places to correct, so I was trying to be smart as
I found that decls. in comdef is different than in msxml*.tlh, so I decided not to use defaults.
Thanks, anyway.
|
|
|
|
|
Hi, I have a few comboboxes on a form. Let's name them LHS (left hand side) and RHS. Whenever I click LHS, I want RHS to reset to it's 0th element.
However, when I click an element in LHS, LHS resets to it's 0th element but will still show the proper items in RHS even though LHS is reset to it's 0th element. There are no pointers to objects being used.
What could be a culprit of this problem? Some windows message? I checked the message maps in the class wizard and combo messages are cleared (except CBN_SELCHANGE, of course).
|
|
|
|
|
When you click on left combo then values of this combo rest to zero,right?
|
|
|
|
|
but i don't think the problem is there
Run-Time Check Failure #2 - Stack around the variable '_Lk' was corrupted.
HEAP[framework(debug).exe]: Heap block at 00CA73D8 modified at 00CA7428 past requested size of 48
Windows has triggered a breakpoint in framework(debug).exe.
This may be due to a corruption of the heap, and indicates a bug in framework(debug).exe or any of the DLLs it has loaded.
The output window may have more diagnostic information
this error just occured out of the blank.
the project is a loader of 3ds files and making a nice scene with some communication through com port with a haptic device. everything worked great till this morning.
maybe some one can give me a push into the right direction or a request of the info he needs from me to point out where the problem could be.
thnx in advanced
Ewart ten Brink
|
|
|
|
|
Hello,
i recive sometimes this message, and only when i want to debugg my app, and i dont know why they is shown!
Can any one explain me what can be an reason for that message.
I dont have any breakpoints set i my sourcecode!
regards
break;
|
|
|
|
|
break; wrote: User breakpoint called from code at
It is as message says. If some memory access violation occurs, this message pops-up.
|
|
|
|
|
Hi,
thanks very much!
I solve them now!
break;
|
|
|
|
|
break; wrote: I solve them now!
how ? please share !
|
|
|
|