[V4Rb 2] VDatabase.Close

Charles Yeomans yeomans at desuetude.com
Wed Jun 1 13:50:51 CDT 2005


On Jun 1, 2005, at 1:32 PM, Ruslan Zasukhin wrote:

> On 6/1/05 7:31 PM, "Charles Yeomans" <yeomans at desuetude.com> wrote:
>
>>> Charles, I am not sure why you think that there should not be a
>>> database close method. Or am I misunderstanding? Imagine a program
>>> that can open multiple databases in the course of an execution, think
>>> databases as different documents or datasets. If there was no option
>>> to close a database, any of the databases would stay open until
>>> program quits, requiring substantially more resources. If users says,
>>> he/she is done with a given dataset (database), we should be able to
>>> close it and free resources for another one.
>>
>> Sure.  And a database should be closed when the object is destroyed, 
>> as
>> I say in another message.  I shouldn't need to call VDatabase.Close
>> explicitly in REALbasic, because REALbasic has destructors, as opposed
>> to Java, for example.
>
> Charles,
>
> What you try point is not very correct. IMHO.
>
> IT will be correct IF constructor do automatic open().
> But it not do this.
>
> Technique which you describe is very common for C++ developers.
>     constructor do some action
>     destructor do its alternative.
>
> I will not explain advantages of this technique.
> They are described in the "C++ PL" of Stroustrup.

Yes; I have read that section very carefully.  The use of the 
constructor for acquisition certainly appeals to symmetry, but the key 
point of the technique is the use of the destructor to release the 
resource.  Suppose you're writing some sort of socket class.  Then you 
would not want to attempt to acquire the resource in the constructor, 
because socket connections can fail for many reasons, and generally a 
constructor should raise an exception if it fails (although one could 
instead craft a better definition of "succeed" in this case).  But you 
would still want the destructor to release the port.
>
> MAY BE btw, this technique can be useful for RB developers!
> I think 100% can be used. Than more that now RB have exceptions..

It certainly is useful for Rb; I use it a lot, and so does the Rb 
framework.  Classes like BinaryStream, TextInputStream etc.  use this 
scheme.

--------------
Charles Yeomans



More information about the Valentina mailing list