Everyone a great god, and I will use MATLAB com components way. M function generates the DLL packaging, and then call in the vb.net, the program is as follows, loading at the interface between the I initialized (due to the slow initialization, so chose the initialization, in loading the window without initialization before the subsequent calls), then click the button "1" and "2" button is can use different parameter has been initialized function called, but I have found in the process of debugging, when using the button button 1 and 2, after repeated calculation will pop-up prompts "to try to read and write protected memory, this time can't continue to use, can only be opened closed software again and again, I ask you a great god this is due to repeated use calculation_function1 function? What should I do with can avoid this problem? In this first thanked,
Public Class Form1
Public calculation_function1 As add_com. Jisuan 'reference DLLS
Dim As Double c
'interface load
Private Sub Form1_Load (sender As Object, As EventArgs e) Handles MyBase. Load
Calculation_function1=New add_com. Jisuan 'load when initializing
End Sub
1
'buttonPrivate Sub Button1_Click (sender As Object, As EventArgs e) Handles for. Click
Calculation_function1. Add (1, c, parameter 1, parameters of 2)
End Sub
'button 2
Private Sub Button2_Click (sender As Object, As EventArgs e) Handles Button2. Click
Calculation_function1. Add (1, c, three parameters, parameter 4)
End Sub
The End of the Class
CodePudding user response:
Estimation is you parameters passed in, structure or the length of the array is wrong, cause memory read crossing the line
CodePudding user response:
reference 1/f, guiyang horse Ma Shanfu plugging waterproof engineering professional maintenance of swimming pool response: you parameter passed in is, structure or the length of the array is wrong, resulting in memory read cross-border Thank you, I tried this, every time calculation using the same parameters, after repeated calculation, still will be prompted to this "to try to read and write protected memory problems, front several times can be calculated using the same parameters and get the right results, but suddenly behind one report this error, CodePudding user response:
Before each call can initialize it again? CodePudding user response:
Loved the reference 3 floor response: before each call can initialize it again? initialization because the speed is slow, so I just put it on the load form, I now use the compromise is joined the try, if the catch to memory mistake, Nothing about it and then GC. Collect, followed by the re-initialization and call again,,, CodePudding user response:
Don't sink, oneself the top post CodePudding user response:
The general is not problem of vb.net, encapsulated matalb components may not be perfect, or repeated calls to com components when com components are still in the calculation CodePudding user response:
Agree with upstairs,. What is the content of the M function? Can you send to? CodePudding user response:
What code itself so simple you may have a problem, should first reaction is the DLL error. Literally analysis, it is called multiple times to produce multiple threads access the Shared memory conflict. Simple point said. You two buttons at the same time, would be a problem, because the first operation result, haven't calculate the second operation calls in the past, will inevitably have some conflicts, unless you function design is the multithreading and does not depend on each other. Should set up a return value, the calculation process is complete, to the next call. CodePudding user response:
refer to the eighth floor raynors response: what code itself so simple you may have a problem, should first reaction is the DLL error. Literally analysis, it is called multiple times to produce multiple threads access the Shared memory conflict. Simple point said. You two buttons at the same time, would be a problem, because the first operation result, haven't calculate the second operation calls in the past, will inevitably have some conflicts, unless you function design is the multithreading and does not depend on each other. Should set up a return value, the calculation process is complete, to the next call. Thank you, you said this means I should be in after the completion of the first returns a single call to inform complete variables and then to the next click operation? I am actually after each call in matlab wrote a pop-up window to inform calculation is complete, then every time I click on the button operation is click again only after complete the notice for computing, CodePudding user response:
references 9 f rabiboy response: Quote: refer to the eighth floor raynors response: What code itself so simple you may have a problem, should first reaction is the DLL error. Literally analysis, it is called multiple times to produce multiple threads access the Shared memory conflict. Simple point said. You two buttons at the same time, would be a problem, because the first operation result, haven't calculate the second operation calls in the past, will inevitably have some conflicts, unless you function design is the multithreading and does not depend on each other. Should set up a return value, the calculation process is complete, to the next call. Thank you, you said this means I should be in after the completion of the first returns a single call to inform complete variables and then to the next click operation? I am actually after each call in matlab wrote a pop-up window to inform calculation is complete, then every time I click on the button operation is once again only after complete the notice for computing, click on the Monitor the memory usage, If a calculated growth, after the release, will be a memory leak problem CodePudding user response:
refer to 6th floor irix2008 response: this is not a general problem of vb.net, encapsulated matalb components may not be perfect, or repeated calls to com components when com components is still in calculating Thank you, I'm calling DLL after complete calculation will return a result, when I was in executing code, after the completion of the call at this time if can return results and correct, then I click on to the next, what method still see the com components can track whether performed? I understand after it returned to the results, should be completed even running, CodePudding user response:
references to the tenth floor raynors response: Quote: references 9 f rabiboy response: Quote: refer to the eighth floor raynors response: What code itself so simple you may have a problem, should first reaction is the DLL error. Literally analysis, it is called multiple times to produce multiple threads access the Shared memory conflict. Simple point said. You two buttons at the same time, would be a problem, because the first operation result, haven't calculate the second operation calls in the past, will inevitably have some conflicts, unless you function design is the multithreading and does not depend on each other. Should set up a return value, the calculation process is complete, to the next call. Thank you, you said this means I should be in after the completion of the first returns a single call to inform complete variables and then to the next click operation? I am actually after each call in matlab wrote a pop-up window to inform calculation is complete, then every time I click on the button operation is once again only after complete the notice for computing, click on the Monitor the memory usage, If a calculated growth, not after the release, will leak problems I found when I was in the debug, sometimes using GC. Collect recycling memory is feasible, sometimes still complains, CodePudding user response:
references to the tenth floor raynors response: Quote: references 9 f rabiboy response: Quote: refer to the eighth floor raynors response: What code itself so simple you may have a problem, should first reaction is the DLL error. Literally analysis, it is called multiple times to produce multiple threads access the Shared memory conflict. Simple point said. You two buttons at the same time, would be a problem, because the first operation result, haven't calculate the second operation calls in the past, will inevitably have some conflicts, unless you function design is the multithreading and does not depend on each other. Should set up a return value, the calculation process is complete, to the next call. Thank you, you said this means I should be in after the completion of the first returns a single call to inform complete variables and then to the next click operation? nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull