Struct contains a function and object to be handled by the function in C# .Net -
I am trying to create a structure that has the function and an object controlled by that function. For example:
Public representative Zero MyFunc (object o); Public structure maida {public object o; Public MyFunc func; Public MyData (Object O, MyFunk Throw) {this.o = o; This.func = func; } Public Handlines () {Throw (o); }} The purpose of this structure is to use any function to handle any data.
I wrap this structure into an IntPtr data type and send it to each other
Prepare Private Zero Form (Object O, MyFunk Funk) {MyData MD = New Myadata (o, throw); Int size = Marshal.SizeOf (md); IntPtr wParam = Marshall. AllocHGlobal (size); Martial StructureToPtr (MD, WPARM, False); DoJob (wParam); } Private Zero DoJob (IntPtr wParam) {if (wParam! = IntPtr.Zero) {type type = MyData}; Maidata MD = (MyData) martial.tterstrokes (P, type); Md.HandleData (); Sometimes I get an error: 1) "[System.RuntimeType] = {name = expression can not be evaluated because the code of the current method is optimized. FullName = not evaluating expression Because the code of the current method is optimized.} In the Handlat Data Function "
2), Function Case charge garbage has been collected and is not able to work properly. As:: Manage Debugging Assistant 'Callback Onculted Delay' has detected a problem
Note: I have not checked the "Optimization Code" in the property of the project.
< Div class = "post-text" itemprop = "text">
Example without a complete code and a clear explanation of what you are actually trying to achieve here, it is impossible to ensure that the best what is the answer. He said, obviously, the entire plan seems crazy to me IntPtr ? seriously?
I do not see anything in your question which describes a problem that can not be completed by wrapping the representative and objecting to the new representative object more easily is.
Example:
Prepare Private Zero Form (Object O, MyFunk Throw) {Dozab ((=) Funk (O)); } Private Zero DoJob (action wParam) {if (wParam! = Null) {wParam (); }}
Note that in your original code, if only one reference has been left in your object and the representative is in the block without you, then they may be < / Em> actually GC'Ad, as they will not be accessible by any managed reference (which cares about GC, is the only thing).
Also keep in mind that objects are still accessible through a managed reference, even if the objects in GC memory (such as compile the heap to compact) move You can interpret the values copied in the memory storage blocks without any fixed memory.
If you want to be used in the managed code and object in your program, you want to avoid these problems.
(I also note that your code example is not valid even as your DoJob () parameter is named wParam But the variable check and martial that you have been refunded in a managed stock is named p .)
Comments
Post a Comment