Am 07.05.2021 um 00:17 schrieb Ryan Joseph via fpc-devel:

On May 6, 2021, at 4:05 PM, Sven Barth via fpc-devel 
<fpc-devel@lists.freepascal.org> wrote:

Other than that, you're right and what Ryan is trying to do is definitely the 
intended purpose of try ... finally.

Is there any runtime code involved with try..finally or does it just reorganize 
the code to run at the end of the block? My understanding of the defer keyword 
is that is was just a fancy way to move some code into a block which always 
gets run with a function exits.
It depends on the platform. In general FPC uses setjmp/longjmp based exception handling, thus there is a slight penalty in setting up the exception frame (no matter if "finally" or "except").

In case of Win32 and Win64 the OS' Structured Exception Handling functionality is used. On i386-win32 there is still a runtime overhead due to how exceptions are managed, but on x86_64-win64 and aarch64-win64 (and in theory also arm-wince and arm-win32, but we have no ARM support for SEH yet (and arm-win32 isn't implemented yet :P )) this is done through meta data located in the PE file (the .pdata and .xdata sections) which allows for an implicit setup of the frames and thus there'll only be a penalty if an exception occurrs (cause the OS and the exception handling code will have to parse that data).

Trunk also supports POSIX exceptions on selected *nix based systems, though I haven't looked in depth yet in how far they incur a runtime penalty (also they need to be enabled by enabling them in the compiler and then recompiling everything, cause they're still experimental).

Regards,
Sven
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to