Re: [RESOLVED] Memory leak?
yes im still interested on whats wrong VladimirF
how can i prevent the variable from getting overwritten?
im using VC 2008 , no warnings about this :(
Re: [RESOLVED] Memory leak?
Quote:
Originally Posted by
Cpp_Noob
how can i prevent the variable from getting overwritten?
You can't. Just don't (ever) return a pointer to local variable.
In your case, you could declare that
in your main() function, and pass its pointer to GetVolumeID().
Or what Paul said.
Re: [RESOLVED] Memory leak?
Quote:
Originally Posted by
VladimirF
Or what Paul said.
+1.
Why not leverage C++ and use string classes instead of the raw char* and string functions?
You'll end up making your code cleaner and won't spend time tracking down issues with manually manipulating the strings yourself.
Some programmers consider it to be a source of pride and feel that they HAVE to manually manipulate strings. Other programmers are in the mindset where they want to use the tools available (like string classes) and are more interested in solving the challenges of their particular program rather than spending time debugging the mundane.
It's one thing to understand raw string manipulation while learning (and it's a good thing), but IMO you'll want to get off that bus as soon as possible and get on the using string classes bus.
Re: [RESOLVED] Memory leak?
Quote:
Originally Posted by
Arjay
Some programmers consider it to be a source of pride and feel that they HAVE to manually manipulate strings. Other programmers are in the mindset where they want to use the tools available (like string classes) and are more interested in solving the challenges of their particular program rather than spending time debugging the mundane.
There was a discussion here a while back on C++ programmers using STL and other libraries over coding their own routines. Basically some people were making the claims that by using STL, string classes, etc., you don't learn the other lower-level parts of C++ to a great extent. I think this is what a lot of this "do everything myself" attitude comes from -- if you use the C++ library, you're a "stupid" programmer who can't write low-level code.
To that I responded to that by saying "try to find such a programmer".
Every single programmer I know, and I bet most, if not all the programmers that primarily uses STL to do advanced work already know how to handle dynamically allocated memory properly and appropriately, how to write a map or linked list class if necessary, etc. You will be hard-pressed to find in the industry an STL-centric C++ programmer who doesn't know how to write low-level code. If you can find one, that is one rare individual.
Regards,
Paul McKenzie
Re: [RESOLVED] Memory leak?
I agree. I believe the thought is that if a programmer can code the low level things, then the programmer can learn and code anything at a higher level.
Unfortunately, often times there ends up being programmers that don't make that transition and prefer for what ever reasons to stay at the lower level.
Re: [RESOLVED] Memory leak?
Quote:
Originally Posted by
Arjay
I agree. I believe the thought is that if a programmer can code the low level things, then the programmer can learn and code anything at a higher level.
To that, there are a lot of "low-level" programmers who's eyes glaze over when they look at STL code. They have no idea where to start or what it means. In many instances, you can forget about trying to get these programmers to write code at a higher level using algorithms, iterators, etc. It just isn't going to happen, either because they just don't understand it, or they stick with what they know, or both.
This scenario by far happens more often than the other scenario of a brilliant C++ programmer who uses STL, and cannot write low-level code. I will be daring and make the claim that you cannot find any advanced C++ programmer who uses STL and the C++ library who cannot write 'C' style low-level code.
Regards,
Paul McKenzie
Re: [RESOLVED] Memory leak?
Quote:
Originally Posted by
Paul McKenzie
To that, there are a lot of "low-level" programmers who's eyes glaze over when they look at STL code. They have no idea where to start or what it means. In many instances, you can forget about trying to get these programmers to write code at a higher level using algorithms, iterators, etc. It just isn't going to happen, either because they just don't understand it, or they stick with what they know, or both.
This scenario by far happens more often than the other scenario of a brilliant C++ programmer who uses STL, and cannot write low-level code. I will be daring and make the claim that you cannot find any advanced C++ programmer who uses STL and the C++ library who cannot write 'C' style low-level code.
Regards,
Paul McKenzie
that is sooo true Paul McKenzie , most of my codes are "low level" and my eyes do glaze when looking over at STL code.