Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Mimic rtlMoveMemory for Speed

Mimic rtlMoveMemory for Speed

Scheduled Pinned Locked Moved Visual Basic
csharpdata-structuresperformancequestionannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pugman812
    wrote on last edited by
    #1

    I have replaced most of the for loops with Array.Copy to mimic the functions of the dll call. But this did not have the speed increase that i was looking for. still same processor time at 100 for 3 seconds. I have also tried a few things like encrypting a 1.4 meg file with the 6.0 version of the blowfish program and it takes seconds. I try with the .Net conversion and it take around 10 minutes to do the same thing. Throughout the conversion of this 6.0 project i have had to make many sub procedures to mimic the function of this dll. I believe the extensive use of this procedures are what is slowing me down. The function is pretty cool if i work in .net. I need an outside call to do some of the work for me because my app is straining a little to hard. I need something that does the same thing that the rtlMoveMemory does when you send it something like this Public Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) Dim LongValue as Long = 1415936116 Dim BB() as Byte CopyMemory( BB(0), LongValue , 4) and what this does is turn this number into binary looks like this BB(0) = 116 : BB(1) = 120 : BB(2) = 101 : BB(3) = 84 in the byte array. I also need a function that does this process in reverse. I had to mimic this with extensive for loops to check each bit. If i could find an outside call to do this same thing. I also found out if the value is greater than 2147483648 which is 2 ^ 31 and is also the highest value bit in a 32 bit number. the function causes the value to go negative and subtract any other amount that the bits equal preceding that last bit. If there is any outside funtion can be used that would speed up my code. I really need to know because with the .net conversion that i am using now. If i didnt have a 6000 RPM Fan i would cook my P4 2.8 GHZ Processor. Oh yes a article on application throttling would be great too if anyone knows where i could read one.

    D 1 Reply Last reply
    0
    • P Pugman812

      I have replaced most of the for loops with Array.Copy to mimic the functions of the dll call. But this did not have the speed increase that i was looking for. still same processor time at 100 for 3 seconds. I have also tried a few things like encrypting a 1.4 meg file with the 6.0 version of the blowfish program and it takes seconds. I try with the .Net conversion and it take around 10 minutes to do the same thing. Throughout the conversion of this 6.0 project i have had to make many sub procedures to mimic the function of this dll. I believe the extensive use of this procedures are what is slowing me down. The function is pretty cool if i work in .net. I need an outside call to do some of the work for me because my app is straining a little to hard. I need something that does the same thing that the rtlMoveMemory does when you send it something like this Public Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) Dim LongValue as Long = 1415936116 Dim BB() as Byte CopyMemory( BB(0), LongValue , 4) and what this does is turn this number into binary looks like this BB(0) = 116 : BB(1) = 120 : BB(2) = 101 : BB(3) = 84 in the byte array. I also need a function that does this process in reverse. I had to mimic this with extensive for loops to check each bit. If i could find an outside call to do this same thing. I also found out if the value is greater than 2147483648 which is 2 ^ 31 and is also the highest value bit in a 32 bit number. the function causes the value to go negative and subtract any other amount that the bits equal preceding that last bit. If there is any outside funtion can be used that would speed up my code. I really need to know because with the .net conversion that i am using now. If i didnt have a 6000 RPM Fan i would cook my P4 2.8 GHZ Processor. Oh yes a article on application throttling would be great too if anyone knows where i could read one.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Your not going to find an equivelnet function in the .NET Framework. This is because the execution environment is MANAGED. This means that any object can be picked up and moved AT ANY TIME without you knowing it. You could write managed code to get around this, but it would also take time to execute this extra code, again slowing your app down tremendously because you have to call the Marshaler to pin the object in place, do your memory copy, then unpin the object. Pinning is a notoriously slow process, just like calling into unmanaged code, because of the overhead of converting the object from managed to unmanaged and back. As a side to your 2^31 bit problem. Use UInt32 data types instead of Int32's or Integers (same as Int32). UInt32 is an unsigned 32 bit integer, where Int32, or Integer, is a signed 32 bit integer. The 1 bit being used for the sign... Sometimes converting code instruction-by-instruction is not the most efficient method. Sometimes you have to rewrite an entire function from scratch to accomplish the same thing... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups