|
 |
Warp wrote:
> The class constructors, assignment and destructor help in automatizing
> the internal memory management of the vector.
>
> You can write your own dynamic data container as a class in the exact
> same way as std::vector and the other STL containers, which will be safe
> and will automatically manage its memory.
But presumable you'd need to know what you're doing first. ;-)
> And not only memory. There are also other resources which can be
> automatically managed with classes.
Mmm, that's nice.
> Unless I'm completely mistaken, this is not something you can achieve
> in Java. (In Java you have to close files explicitly and catch all
> possible exceptions which might otherwise bypass that closing.)
Actually, for reasons beyond my comprehension, if a Haskell program
halts abnormally, all files are closed, but not necessarily *flushed*.
Like, WTF? *Why?* Anyway, basically you have to write some code to catch
the exception and close the file before rethrowing it. It's an extra 3
lines of code, but you still have to remember to type them...
>> I've never actually seen a programming environment with manual memory
>> management *and* dynamically resizable collections. The two are usually
>> muturally exclusive.
>
> Well, it's not like *all* resources in C++ are managed manually.
> More precisely, stack-allocated objects are managed automatically. Which
> is exactly the reason why automatic management heap-allocated objects
> becomes possible through these stack-allocated objects.
Indeed. I've not seen this in any other OO language.
>> Then again, I'm not really sure what the story is if you try to put
>> user-defined data types into a vector...
>
> If the user-defined type doesn't allocate memory in itself, or if it
> does but manages it properly, there shouldn't be any problems.
Sounds good to me! ;-)
Post a reply to this message
|
 |