From: | Jesse McClusky |
Date: | 29 Aug 2000 at 03:19:28 |
Subject: | Re: AMIOPEN: Object allocated on stack - init and/or open |
> From: "Aaron Optimizer Digulla" <digulla@hepe.com>
>
> Quoting Jesse McClusky <thought@weblink.org>:
>
> > What objects need _new then open???
> > Generally speaking, from what I've seen, the correct procedure is to
> > call _new then init to create it, and deinit then _delete to free it.
> > HOWEVER, many classes also have two additional tools called
> > open and close. Open calls _new, then init, returning the new class
> > instance. Close calls deinit, then _delete.
>
> In that case, I'd like to ask why not all classes have open/close (or
> do they) ? Since you always have to call _new+init (and always in
> that order), I don't see a good reason to separate these two.
> I would even suggest to select one name (_new, init, open, create)
> and let that do anything necessary to create an object (like
> in Java, C++, Python, Perl and anywhere else).
It's actually to make interaction with C++ easier. C++ uses a new
(_new) operator to allocate the memory for a class before it exists,
and a delete (_delete) operator to de-allocate the memory. It also
has a _separate_ operator/method for initialization, called a
constructor, and de-initialization, called a destructor (it actually can
have several of both).
The problem comes in in that the constructor (in this case, the
default is init) can take any number of arguments, depending on
the class. The new and delete operators, however, always have
a fixed number of args.
However, I'm not sure why the _new tool doesn't automatically
call init, and the _delete tool doesn't automatically call deinit.
The only thing I can think of is that they somehow thought that
someone somewhere would want to alloc/dealloc the memory
independent to initializing/deinitializing it, though I can't think of
a single reason why. Put that on the list to ask Tao. (:
Jesse
Subscribe/Unsubscribe: open-request@amiga.com
Amiga FAQ: http://www.amiga.com/faq.html