2/18/2017 7:11 AM | |
Joined: 7/6/2008 Last visit: 3/10/2023 Posts: 11 Rating:
|
Dear Experts, I'm developing my project using CFC, for this project I need to create my own functions with inputs and outputs that I will use repeatedly in the project. My question is which choice is efficient in terms of perfomance, to create the functions as FC or as FB. It's not a must for some of the blocks that I will create to have instance DBs that's why I can create them as FC. but once compiled to stl which way is efficient. If I use create them as FB then an instance DB is created for each call insert, which looks like waist of memory resources. On the other hand, when I create as FC and look to the compiled stl version I can see that all input variables are transferred to local memory variables and then are inserted as actual variables of the FC. That looks like a waist of performance. In FB case it seems that actual variables are transferred to the fields of the instance DB just before the UC call of the FB and no insertion of actual variables, it seems more efficient. I hope I could make my question clear. Prompting for your comments ------------------------------------------------------------------------------------------ |
Last edited by: ibo at: 2/18/2017 7:17:42 AMLast edited by: Min_Moderator at: 2/20/2017 12:40:15 PMNew subject after splitting |
|
2/24/2017 8:48 AM | |
Joined: 7/6/2008 Last visit: 3/10/2023 Posts: 11 Rating:
|
thank you for your comments, well, I'm not exactly sure whether FC takes the reference of the parameter or its value to the local memory which is most probably is the stack of the core computer. if we can be sure about this point I think we can be one step further towards the answer of my main issue. In a specific case where the parameters of the function are constants, but of course of different values for each instance call of the function, using FB for the first glans looks more efficient since I had seen that the CFC compiler stores those parameters as the values of the instance DB. They're written once by the compiler and not transferred cyclically. In the case of FC those constants are transferred cyclically with every call. So for that specific case where we have constant input parameters FB seems a winner. Still we have two concerns to consider. The first is with variable parameter as inputs of the function, what's the estimate of performance in terms of passing the parameters to FC or FB. The second concern is related to the code inside the function itself, accessing the IO parameters as instance DB elements or accessing the parameters as local variables of the FC, which is more efficient. I had a closer look to the generated STL code of the CFC compiler, attached you can see the difference in passing the constant parameters for both FC and FB. That was where I discovered that the constant parameters are not transferred cyclically to the FB but just used as the values of the instance DB parameter values. Attachmentcodes.pdf (98 Downloads) |
Follow us on