<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2016-04-14 10:50 GMT+02:00 Michael Van Canneyt <span dir="ltr"><<a href="mailto:michael@freepascal.org" target="_blank">michael@freepascal.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
<br>
On Thu, 14 Apr 2016, Mazola Winstrol wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Recently i did some maintenance in a code of a colleague. I realized that<br>
he designed several classes with interface support so he do not need to<br>
protect the code blocks with try..finally to ensure that the instances are<br>
released from memory.<br>
<br>
Theoretically, which solution has higher performance? The traditional<br>
approach (code protected try..finally) or classes with interfaces (no need<br>
to protect the code. by otherside, classes with interfaces support have<br>
lock operations)?<br>
<br>
</blockquote>
<br></span>
It should be exactly the same. As soon as interfaces are used the compiler inserts an implicit try...finally in a procedure.<br>
You can see this if you step through the code with GDB, the execution point<br>
will jump to the end of the procedure and then back to the beginning...<span class="HOEnZb"><font color="#888888"><br>
</font></span><br></blockquote></div><br></div><div class="gmail_extra">I would venture, that manually adding try finally would give you better performance than using interfaces at the cost of writing more code and therefore less clear and more error-prone source.<br><br></div><div class="gmail_extra">If you use interfaces, the compiler also adds reference counting, which you don't have if you free the objects at the right places.<br><br></div><div class="gmail_extra">It is not sure if you can measure the difference in performance though.<br><br></div><div class="gmail_extra">Vincent<br></div><div class="gmail_extra"><br></div></div>