Re: [RESOLVED] Why does this code leak memory?
Quote:
Originally Posted by Paul McKenzie
Which means we would have timing tests, comparisons, and actual code showing the vector implementation, all without the vitriol and bravado.
Regards,
Paul McKenzie
And it sounds like someone is getting too worked up on holding onto a bunch of projects that use STL, and is less willing to let go of archaic and to go with new technological ideas.
Remember, it's the CRT and STL and their caveats that have prevented standard C++ from going further than it has. The only way to circumvent them, is to let go of them. I am not trying to start a fuss, there are alot of projects that depend on STL, and because alot of people use them, they get 'attached' to the code they write that way.
Unfortunately for those people... Sticking with STL means that you will never have a full fledged library that you want, due to the very fact that the entire industry only agrees on one thing when it comes to the standard... and that's to disagree.
You cannot build a framework around STL and expect everyone to use it, because there are alot of programmers out there that hate STL, myself being one of them.
IMHO, I see it this way. There are 3 paths to take... You can stick with the 'standard' and open source movements, and lean towards Apple as well... Or you can embrace MS and .NET ...
The first two I view as stupid. And yes, I will take what Paul said about 99% of other people and discard it. (and it's not 99%, it's actually quite a bit lower than that) not having a problem with vector. Yeah they do, it's a template. Templates have overheads and things about them that every programmer hates. Paul, please use more rational thinking when you make a statement. This is the very proof you are not thinking clearly, and are running on emotion because of your attachment to vector, and how much you take it seriously trying to 'run with the standard'. I know that too, I see how much you refer to it. So calm down, and take a chill pill.
Why do I discard that? It doesn't apply to ME, that's why.
My situation is what I believe to be the smart one. Take the road of rolling my own framework that takes the ideas of old and new and goes down the right path. The standard people 'hate' those that reinvent (not really, generally though, it's a true statement)... And MS hates those that do something better than them (those that either go against their ideas, or those that implement them better than they do)...
I believe my path is the right one, due to the fact it's idealogy takes the route that it does not make a choice to go with either side.
Re: [RESOLVED] Why does this code leak memory?
Quote:
And it sounds like someone is getting too worked up on holding onto a bunch of projects that use STL, and is less willing to let go of archaic and to go with new technological ideas.
What are these "new technological ideas"?
Quote:
Remember, it's the CRT and STL and their caveats that have prevented standard C++ from going further than it has.
Could you elaborate? A comprehensive online essay would make for a good line, if feasible, especially if it is by a noted expert in C++.
Quote:
Unfortunately for those people... Sticking with STL means that you will never have a full fledged library that you want, due to the very fact that the entire industry only agrees on one thing when it comes to the standard... and that's to disagree.
I do not understand your reasoning. If people cannot agree when it comes to the standard, why would they agree to anything else?
Quote:
You cannot build a framework around STL and expect everyone to use it, because there are alot of programmers out there that hate STL, myself being one of them.
But you cannot build any framework and expect everyone to use it. Such an expectation is surely unrealistic. If you cater to one crowd, you will surely step on the toes of another crowd.
Re: [RESOLVED] Why does this code leak memory?
Quote:
Originally Posted by laserlight
What are these "new technological ideas"?
Could you elaborate? A comprehensive online essay would make for a good line, if feasible, especially if it is by a noted expert in C++.
I do not understand your reasoning. If people cannot agree when it comes to the standard, why would they agree to anything else?
But you cannot build any framework and expect everyone to use it. Such an expectation is surely unrealistic. If you cater to one crowd, you will surely step on the toes of another crowd.
Okay, this would probably be a good idea to go to another thread on this issue. However, I would like to state take a look at the edit of my last post.
Re: [RESOLVED] Why does this code leak memory?
Quote:
Originally Posted by JamesSchumacher
You cannot build a framework around STL and expect everyone to use it,
Everyone means 100%. Where did I ever state anything is 100%? Not everyone will use anything in C++. Not everone will use facets. Not everone will use iostreams. Not everyone will use <complex>. Not everyone will use .. etc. .etc...
The common denominator when asked a question concerning C++ is to mention the standard components first and maybe boost, i.e. components that have been tested fully in the user community and are standard or as close to standard as possible. The reason is that the poster asking the question has plenty of resources available to them when it comes time to use the suggestions given to them.
Niche coding and pathological cases may be used when asked questions pertaining to them. If the OP mentioned "vector has these issues, so I decided to try this instead", then that is a different story. But just cluttering a thread with coding that no one really knows what it does, how it works, who coded it, who tested it, whether any claims are true, etc. is really non-productive when a straightforward answer is warranted.
Regards,
Paul McKenzie
Re: [RESOLVED] Why does this code leak memory?
Quote:
Originally Posted by JamesSchumacher
Paul, please use more rational thinking when you make a statement. This is the very proof you are not thinking clearly, and are running on emotion because of your attachment to vector, and how much you take it seriously trying to 'run with the standard'. I know that too, I see how much you refer to it. So calm down, and take a chill pill.
All of this talk, and all I mentioned to the OP was to use std::vector?
It seems you are projecting your own emotions onto me and you are the one that needs calming down.
Regards,
Paul McKenzie
Re: [RESOLVED] Why does this code leak memory?
No, my original intent was actually myself getting tired of seeing what I see as inferior (as the fact, it would be possible through specialization as well - however, that's rolling your own at that point) - meaning std::vector, being ALWAYS the solution put out there.
In case you do not know Paul, I do like stringstreams. And any chance that STL is a possibility of use, I do encourage the use of stringstreams. However, NOT vector.
And actually Paul, this thread started about the possibility of a memory leak, and I brought up the point it would be better to learn the proper use of new/delete.
This isn't an issue of std::vector, I was the one who initially made the statement referring to what the user asked. The importance of new/delete is more important than knowing how to use std::vector.
Rolling your own class allows you to learn the caveats and generality of what it takes to build what std::vector does, that knowledge is more important that using std::vector. std::vector is just a class, the knowledge allows you to use what you learn in building others things than just a vector replacement.
Re: [RESOLVED] Why does this code leak memory?
Quote:
Originally Posted by JamesSchumacher
No, my original intent was actually myself getting tired of seeing what I see as inferior
That is your opinion. For most purposes, vector is far more preferable than the new/delete coupled with extreme logic to get the two working together.
Quote:
meaning std::vector, being ALWAYS the solution put out there.
For the OP's purposes, it was a solution. Read his last response. Anyway, there is nothing that is always a solution.
Quote:
In case you do not know Paul, I do like stringstreams. And any chance that STL is a possibility of use, I do encourage the use of stringstreams.
And others do not like streams. Also, iostreams is not STL. The streams have been part of C++ before STL was even devised.
Quote:
However, NOT vector.
That again is your opinion. I would rather value the opinion of noted C++ experts, coupled with my own experience than something out of the blue with no documentation, peer review, testing, etc.
Quote:
And actually Paul, this thread started about the possibility of a memory leak, and I brought up the point it would be better to learn the proper use of new/delete.
And I already stated that the OP knows how to use new and delete -- did you read the original code? The OP carefully tried to pair each new[] with delete[]. This is all that is required to know how to use it. The problem is that in the pairing of these two calls, the logic of the code gets in the way, making new and delete usage prohibitive. I am repeating myself -- did you not read my earlier post?
Quote:
This isn't an issue of std::vector, I was the one who initially made the statement referring to what the user asked. The importance of new/delete
The importance is when to use it, and when it is counter-productive to use it.
Regards,
Paul McKenzie
Re: [RESOLVED] Why does this code leak memory?
It's all in the eyes of the beholder as you say. I am saying that is not the case. Simply put, by factual data of the thread in hand.
My point is that he was worried about a memory leak, when actuality it was a different problem all together. So the problem was not that he ' wasn't using vector ', the problem was that he was misusing new/delete.
In that sense, proposing std::vector is NOT the solution Paul.
Re: [RESOLVED] Why does this code leak memory?
Quote:
Originally Posted by JamesSchumacher
In that sense, proposing std::vector is NOT the solution Paul.
I will judge by the OP's satisfaction as to what I proposed is a solution or not.
As to giving an answer based on a question: I would bet that a good percentage, maybe close to half of responses on CodeGuru to any poster's question does not look like the OP's original code or design.
If you saw someone use a screwdriver as a hammer, do you give him a hammer, or do you show him how to hit a nail with a screwdriver properly? I'll do the former.
Regards,
Paul McKenzie
Re: [RESOLVED] Why does this code leak memory?
James,
So are you going to post enough of your listbox data class so any real determination
can be made about relative performance if internally implemented with a vector?
Re: [RESOLVED] Why does this code leak memory?
Quote:
Originally Posted by souldog
James,
So are you going to post enough of your listbox data class so any real determination
can be made about relative performance if internally implemented with a vector?
Okay... I am not going to post the source code... However, have you seen a ListBox that can handle 9,000,000 strings or more? RAM seems to be the only limitation for mine.
Screen Capture Video Gotta love 7-zip on compressing MS-CRAM (MS Video 1) screen captures with no audio. :D
And technically, it's not holding 9,000,000 strings. It's holding 9,000,000 CListItem objects via pointers.
.NET? :thumbd: You're not going to see a .NET listbox do that.
Native? :thumb: ;)
Give me 16 gigabytes (this one has 1 gigabyte). 16 x 9 = 144.
I wonder what this code would be like on a 64-bit machine with 16 gigabytes. Could it handle 144,000,000 CListItem objects? :eek:
Re: [RESOLVED] Why does this code leak memory?
Quote:
Originally Posted by JamesSchumacher
Okay... I am not going to post the source code...
So I guess the answer to souldog's question is "no, I have no such code to show you that compares an implementation using vector with what I've done".
Regards,
Paul McKenzie
Re: [RESOLVED] Why does this code leak memory?
Quote:
Originally Posted by JamesSchumacher
As for the dynamic issue... Stack variables cannot be passed to another thread.
Of course they can. It is REFERENCES (or pointers) to stack variables that will cause issues in many cases (where the life of the thread is longer than the life of the stack frame).
ps: I completely agree with Paul. During a coding review, I will outright reject any custom memory management UNLESS it can be documented that a standard implementation (such as an STL container) can not do the job. Developers who submit such items more than once or twice, find themselves looking for new jobs.
Re: [RESOLVED] Why does this code leak memory?
It is perfectly alright to be proud of one's work, James, but your statements in this thread seem a bit over-the-top.
You need to concede on at least the following points:
1) You are not privy to any information that the C++ community is unaware of in their tendency to recommend std::vector.
2) A vector is not a ListBox. Stop comparing them.
I'd elaborate, but I think it's sufficient to say I agree with everything Paul's said so far.
Re: [RESOLVED] Why does this code leak memory?
Quote:
Originally Posted by TheCPUWizard
Of course they can. It is REFERENCES (or pointers) to stack variables that will cause issues in many cases (where the life of the thread is longer than the life of the stack frame).
ps: I completely agree with Paul. During a coding review, I will outright reject any custom memory management UNLESS it can be documented that a standard implementation (such as an STL container) can not do the job. Developers who submit such items more than once or twice, find themselves looking for new jobs.
First of all... Each thread get's it's OWN STACK, therefore you cannot pass sometime that has anything in that thread's stack to another. Passing by value is different (a 32bit integer passed by value reinterpret_cast to the void pointer, that's different - Stop being a smart arse).
As far as comparing... Do you see a LISTBOX that is implemented using std::vector that is capable of that? Alright, case closed. I am not one to show source code out of my closed source projects that I am going to use in projects that I will make money on. Alright, with that said...
It will even handle 10,000,000 + after I let it swap out all the memory to file, and then back into memory after it defragmented it. (took forever to do that, but afterwards... It ran fine with 10,250,000 items in it)
The point is, the ListBox does nothing except use the CListItem container that holds the items. The container stores those 10,250,000 items. (And of course it draws them based on scroll position/etc...)
I do not believe that the default allocator for std::vector will allow you to allocate that many objects. 10,250,000 * sizeof(pointer) + 10,250,000 * sizeof(CListItem) + 10,250,000 * 16 (block size of CAnsiString member of CListItem)