Re: [fpc-pascal] try..finally vs interfaces performance
On 2016-04-14 21:45, Luiz Americo Pereira Camara wrote: > other class > that implements addref method but does not automatically frees the instance > when refcount is zero I always considered that a bit of a hack. But yes, you are right. Regards, Graeme ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] try..finally vs interfaces performance
2016-04-14 10:58 GMT-03:00 Graeme Geldenhuys : > On 2016-04-14 14:15, Marcos Douglas wrote: > > because you gain more than just automatic memory release. > > It is also worth noting that not all Interface usage means “automatic > memory release”. If you use COM-style Interfaces, then yes you get > memory management. Not necessarily, you can use COM interfaces with TComponent or other class that implements addref method but does not automatically frees the instance when refcount is zero Luiz ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] try..finally vs interfaces performance
2016-04-14 10:50 GMT+02:00 Michael Van Canneyt : > > > On Thu, 14 Apr 2016, Mazola Winstrol wrote: > > Recently i did some maintenance in a code of a colleague. I realized that >> he designed several classes with interface support so he do not need to >> protect the code blocks with try..finally to ensure that the instances are >> released from memory. >> >> Theoretically, which solution has higher performance? The traditional >> approach (code protected try..finally) or classes with interfaces (no need >> to protect the code. by otherside, classes with interfaces support have >> lock operations)? >> >> > It should be exactly the same. As soon as interfaces are used the compiler > inserts an implicit try...finally in a procedure. > You can see this if you step through the code with GDB, the execution point > will jump to the end of the procedure and then back to the beginning... > > 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. If you use interfaces, the compiler also adds reference counting, which you don't have if you free the objects at the right places. It is not sure if you can measure the difference in performance though. Vincent ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] try..finally vs interfaces performance
On Thu, Apr 14, 2016 at 10:58 AM, Graeme Geldenhuys wrote: > On 2016-04-14 14:15, Marcos Douglas wrote: >> because you gain more than just automatic memory release. > > It is also worth noting that not all Interface usage means “automatic > memory release”. If you use COM-style Interfaces, then yes you get > memory management. If you use CORBA-style Interface, then no you don’t > get memory management. You're right, well remembered. I use only COM-style Interfaces. Regards, Marcos Douglas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] try..finally vs interfaces performance
On 2016-04-14 14:15, Marcos Douglas wrote: > because you gain more than just automatic memory release. It is also worth noting that not all Interface usage means “automatic memory release”. If you use COM-style Interfaces, then yes you get memory management. If you use CORBA-style Interface, then no you don’t get memory management. Regards, Graeme -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] try..finally vs interfaces performance
On Thu, Apr 14, 2016 at 5:19 AM, Mazola Winstrol wrote: > Recently i did some maintenance in a code of a colleague. I realized that he > designed several classes with interface support so he do not need to protect > the code blocks with try..finally to ensure that the instances are released > from memory. > > Theoretically, which solution has higher performance? The traditional > approach (code protected try..finally) or classes with interfaces (no need > to protect the code. by otherside, classes with interfaces support have lock > operations)? Hi, I don't know the answer but I think should be exactly the same. Even if not, I strongly recommend you to use interfaces instead "try-finally" approach because you gain more than just automatic memory release. Regards, Marcos Douglas PS. I have a blog about Object Pascal. I write about real object-oriented approach. The blog is written in Portuguese but using Google Translate I guess you won't have problems to translate. http://objectpascalprogramming.com/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] try..finally vs interfaces performance
On Thu, 14 Apr 2016, Mazola Winstrol wrote: Recently i did some maintenance in a code of a colleague. I realized that he designed several classes with interface support so he do not need to protect the code blocks with try..finally to ensure that the instances are released from memory. Theoretically, which solution has higher performance? The traditional approach (code protected try..finally) or classes with interfaces (no need to protect the code. by otherside, classes with interfaces support have lock operations)? It should be exactly the same. As soon as interfaces are used the compiler inserts an implicit try...finally in a procedure. You can see this if you step through the code with GDB, the execution point will jump to the end of the procedure and then back to the beginning... Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] try..finally vs interfaces performance
On 2016-04-14 09:19, Mazola Winstrol wrote: > Theoretically, which solution has higher performance? Interesting question. As for the answer I have no idea. Why don't you put a quick test together. Loop the code 10,000 or 100,000 times and time the results. Please share your test code and answer if you don't mind. Regards, Graeme -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] try..finally vs interfaces performance
Recently i did some maintenance in a code of a colleague. I realized that he designed several classes with interface support so he do not need to protect the code blocks with try..finally to ensure that the instances are released from memory. Theoretically, which solution has higher performance? The traditional approach (code protected try..finally) or classes with interfaces (no need to protect the code. by otherside, classes with interfaces support have lock operations)? Regards ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal