rtlMoveMemory Dll Call Problem In .NET
-
I figured out fully the functions of this call through the use of for loops. This is great but there is a speed issue when handling the functions of this dll through for loops. I am just wandering if annoy one knows how to make this call work in .NET. The declare in vb 6.0 is
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
This is what i am having to work with. As anyone should know that the datatype is not supported in .net. So i replaced it with the Object datatype. a call to this dll function looks like thisDim bytearray(3) as Byte dim bytearray2(3) as Byte Copymemory(bytearray(0), bytearray2(0), 4)
This function copys all data starting with bytearray2(0) to bytearray(0) then bytearray2(1) to bytearray(1) and so on until it copys 4 times. As you can see this can be done with a for loop. But say you have to run thought that for loop 1000 times. The Dll call is much more efficient. When i do it in the manner that i am now my processor sits at 100 percent for almost 3 seconds while it goes through these loops. In 6.0 using the dll call there is no wait and no processor jump. I need this call to work for program efficiency. Any help would be great. Thank you -
I figured out fully the functions of this call through the use of for loops. This is great but there is a speed issue when handling the functions of this dll through for loops. I am just wandering if annoy one knows how to make this call work in .NET. The declare in vb 6.0 is
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
This is what i am having to work with. As anyone should know that the datatype is not supported in .net. So i replaced it with the Object datatype. a call to this dll function looks like thisDim bytearray(3) as Byte dim bytearray2(3) as Byte Copymemory(bytearray(0), bytearray2(0), 4)
This function copys all data starting with bytearray2(0) to bytearray(0) then bytearray2(1) to bytearray(1) and so on until it copys 4 times. As you can see this can be done with a for loop. But say you have to run thought that for loop 1000 times. The Dll call is much more efficient. When i do it in the manner that i am now my processor sits at 100 percent for almost 3 seconds while it goes through these loops. In 6.0 using the dll call there is no wait and no processor jump. I need this call to work for program efficiency. Any help would be great. Thank youThe problem is you CAN'T use this function on managed objects and variables in .NET. The address you provide is not guaranteed to be the address of your object when the call to CopyMemory if made. The speed issue your having is because your marshaling objects back and forth between managed and unmanaged code. Youe best bet is to trace through the code in VB6, and step by step, follow what happens to the array, then duplicate the steps necessary to perform the same thng in managed code. You'll be writing extra lines of code to do this, but you'll also gain a nice performance benefit by doing it either of there two ways. So instead of CopyMemory from bytearray2 to bytearray0, you would just do:
bytearray(0) = bytearray(2) bytearray(1) = bytearray(3) bytearray(2) = bytearray(4) bytearray(3) = bytearray(5)
You could also do this:
Array.Copy( bytearray, 2, bytearray, 0, 4)
You'll have to test each method to find out which is going to give you the greatest performance benefit, but both will be MUCH better than calling an unmanaged function on a managed object... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome