18.10.2014 Views

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Conta<strong>in</strong>ers 263<br />

• If the objects overlap (share the same storage):<br />

Action on assignment Commentary<br />

Anon := Orig<strong>in</strong>al; Perform the assignment:<br />

'Anon := Orig<strong>in</strong>al;'<br />

Adjust(Anon); Increment the reference count for the object<br />

Anon.<br />

F<strong>in</strong>alize(Copy); Decrement by one the reference count for the<br />

object Copy.<br />

If this is now zero, release the storage that the<br />

object Copy po<strong>in</strong>ts to.<br />

Copy := Anon; Perform the assignment:<br />

'Copy := Orig<strong>in</strong>al;'<br />

Adjust(Copy); Increment the reference count for the object<br />

Copy.<br />

F<strong>in</strong>alize(Anon); Decrement by one the reference count for the<br />

object Anon.<br />

If this is now zero release the storage that the<br />

object Anon po<strong>in</strong>ts to.<br />

• If the objects do not overlap, the follow<strong>in</strong>g optimization may be performed:<br />

Action on assignment Commentary<br />

F<strong>in</strong>alize(Orig<strong>in</strong>al); Decrement by one the reference count for the<br />

object Orig<strong>in</strong>al.<br />

If this is now zero, release the storage that the<br />

object Orig<strong>in</strong>al po<strong>in</strong>ts to.<br />

Copy := Orig<strong>in</strong>al; Perform the assignment:<br />

'Copy := Orig<strong>in</strong>al;'<br />

Adjust(Copy); Increment the reference count for the object<br />

Copy.<br />

Note:<br />

The compiler may generate no code if the target and the source are the same.<br />

When a reference counted item is passed as a parameter to a function or procedure by value, for example:<br />

Procedure<br />

Call of procedure<br />

procedure Put(L:<strong>in</strong> List) is<br />

beg<strong>in</strong><br />

....<br />

end Put;<br />

declare<br />

Colours : List;<br />

Beg<strong>in</strong><br />

Put( Colours );<br />

end;<br />

then only the follow<strong>in</strong>g actions are performed:<br />

Put( Colours )<br />

L := Colours;<br />

Adjust(L);<br />

Commentary<br />

Perform the assignment of colours to the<br />

formal parameter:<br />

'L := colours;'<br />

Increment the reference count for the actual<br />

parameter L.<br />

Note: When the procedure put is exited, f<strong>in</strong>alize will be called on the formal parameter l.<br />

© M A Smith - May not be reproduced without permission

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!