The title quite neatly cancels itself out.
Anyway, I just realized this morning that my C++ projects were all at a standstill, so I hurriedly opened Code::Blocks and stared at my Recent Projects list.
This frightened me, so I went back in time a bit to my old lolcode interpreter (Which you have not seen, yet). It worked, but it had some nasty memory leaks.
Therefore, I replaced most of this:
lines = (char*)malloc(sizeof(char)*lsize));
...
if(lines)free(lines);
(I apologize profusely to blackhole for the trouble I caused over this
exact style of coding)
With this:
lines = new string[num_lines];
...
if(lines)delete[] lines;
This, I assure you, is the 'proper' (and sane) way to do things. Also, std::string is far more useful than a char array. :P
After doing that (And making the program work a bit better), I moved on to Hydra.
A day with HydraSo, I opened my Hydra Library project, and the first thing that struck me was that it was damned messy.
You see, I haven't touched Hydra much in about a month, and during that time I was using (And
enjoying) Java.
So that got me thinking about something the organization of the project, and the overall structure. And once again I wrote a lengthy design document detailing a new way to structure the source code, in a similar way to Java.
This basically means that everything in Hydra <insert arbitrary version number here> will be an Object. I have yet to figure out what this implies.
And with thatForget everything you have just read, and comment.
Or comment and then read.
)
DISASTER AVERTED.If num_lines is constant you should have declared it on the stack. Otherwise, if you want to be coding in modern C++, you should probably use std::unique_ptr for automated cleanup (yes you can use unique_ptr on arrays). The exception is usually when its being thrown around in a tricky situation, or is inside of a class and thus can only be destroyed when the class is destroyed anyway.
The first method is still valid for certain performance critical situations. Note that the first method will generate a large block of memory, whereas the second creates fragmented chunks all over the place. This can be a very important distinction in certain cases (but not yours so its still terrible there).