Functions that are faster than copymemory supercopymemory

Source: Internet
Author: User


'Vb embedded ASM accelerates Memory Data Replication
Option explicit
Private declare sub copymemory lib "Kernel32" alias "rtlmovememory" (lpdest as any, lpsource as any, byval cbytes as long)
Private declare function callwindowproc lib "USER32" alias "callwindowproca" (byval lpprevwndfunc as long, byval hwnd as long, byval MSG as long, byval wparam as long, byval lparam as long) as long
Private declare function queryperformancecounter lib "Kernel32" (X as currency) as Boolean
Private declare function queryperformancefrequency lib "Kernel32" (X as currency) as Boolean
Private opcode (200) as byte, codestar as long, opindex as long
Private Sarr (5000000) as byte, Darr (5000000) as byte

'*************************************** **********************************
*** Module name: supercopymemory VB example
'** Note: All rights reserved for online design of danxin software 2007-2008 (c)
'** Creator: Dan Xin
'** Date: 22:13:43
'** Modifier:
'** Date:
'** Description: supercopymemory (), a function that is faster than copymemory, is applied to high-speed memory replication requirements.
'** Version: v1.0.0
'** Blog address: http://hi.baidu.com/starwork/
'** QQ number: 121877114
'** E-mail: cnstarwork@126.com
'*************************************** **********************************

Public sub supercopymemory (byval lpdest as long, byval lpsource as long, byval cbytes as long)
Callwindowproc codestar, 0, lpdest, lpsource, cbytes
End sub

Public sub asmini ()
Dim I as long
Codestar = (varptr (opcode (0) or & HF) + 1
Opindex = codestar-varptr (opcode (0 ))
For I = 0 to opindex-1
Opcode (I) = & HCC
Next
Addbytetocode & h50: addbytetocode & h53: addbytetocode & h51: addbytetocode & h56: addbytetocode & h57: addbytetocode & h8b
Addbytetocode & h7c: addbytetocode & h24: addbytetocode 28: addbytetocode & h8b: addbytetocode & h74: addbytetocode & h24
Addbytetocode 32: addbytetocode & h8b: addbytetocode & h4c: addbytetocode & h24: addbytetocode 36: addbytetocode & hb8
I = 64
Addlongtocode I: addbytetocode & h8b: addbytetocode & hd9: addbytetocode & HFC: addbytetocode & h3b: addbytetocode & hc8
Addbytetocode & h7c: addbytetocode & H52: addbytetocode & HC1: addbytetocode & he9: addbytetocode & H6: addbytetocode & HF
Addbytetocode & H18: addbytetocode & h46: addbytetocode & h40: addbytetocode & HF: addbytetocode & H18: addbytetocode & h47
Addbytetocode & h40: addbytetocode & HF: addbytetocode & h6f: addbytetocode & H6: addbytetocode & HF: addbytetocode & he7: addbytetocode & H7
Addbytetocode & HF: addbytetocode & h6f: addbytetocode & h4e: addbytetocode & H8: addbytetocode & HF: addbytetocode & he7
Addbytetocode & h4f: addbytetocode & H8: addbytetocode & HF: addbytetocode & h6f: addbytetocode & h56: addbytetocode & H10
Addbytetocode & HF: addbytetocode & he7: addbytetocode & h57: addbytetocode & H10: addbytetocode & HF
Addbytetocode & h6f: addbytetocode & h5e: addbytetocode & H18: addbytetocode & HF: addbytetocode & he7: addbytetocode & h5f
Addbytetocode & H18: addbytetocode & HF: addbytetocode & h6f: addbytetocode & H66: addbytetocode & H20: addbytetocode & HF
Addbytetocode & he7: addbytetocode & h67: addbytetocode & H20: addbytetocode & HF: addbytetocode & h6f
Addbytetocode & h6e: addbytetocode & H28: addbytetocode & HF: addbytetocode & he7: addbytetocode & h6f: addbytetocode & H28
Addbytetocode & HF: addbytetocode & h6f: addbytetocode & h76: addbytetocode & h30: addbytetocode & HF: addbytetocode & he7
Addbytetocode & h77: addbytetocode & h30: addbytetocode & HF: addbytetocode & h6f: addbytetocode & h7e
Addbytetocode & H38: addbytetocode & HF: addbytetocode & he7: addbytetocode & f: addbytetocode & H38
Addbytetocode & H3: addbytetocode & hf0: addbytetocode & H3: addbytetocode & hf8: addbytetocode & h49
Addbytetocode & h75: addbytetocode & HB3: addbytetocode & HF
Addbytetocode & h77: addbytetocode & h8b: addbytetocode & HCB: addbytetocode & h48: addbytetocode & H23
Addbytetocode & hc8: addbytetocode & h74: addbytetocode & H2: addbytetocode & hf3: addbytetocode & ha4: addbytetocode & h5f
Addbytetocode & h5e: addbytetocode & h59: addbytetocode & h5b: addbytetocode & h58: addbytetocode & hc2
Addbytetocode & H10: addbytetocode & H0: addbytetocode & H0
End sub
Public sub addbytetocode (bdata as byte)
Opcode (opindex) = bdata
Opindex = opindex + 1
End sub
Public sub addlongtocode (ldata as long)
Copymemory opcode (opindex), ldata, 4
Opindex = opindex + 4
End sub

'Supercopymemory () function

Private sub commandementclick ()
Dim S1 as currency, S2 as currency
Dim F as currency, T1 as currency
Call queryperformancefrequency (f) 'timing
Call queryperformancecounter (S1)
Supercopymemory varptr (Darr (0), varptr (Sarr (0), 5000000
Call queryperformancecounter (S2)
T1 = (S2-S1)/F
Command1.caption = "time =" & T1
End sub

'----- Copymemory
Private sub command2_click ()
Dim S1 as currency, S2 as currency
Dim F as currency, T1 as currency
Call queryperformancefrequency (f) 'timing
Call queryperformancecounter (S1)
Copymemory Darr (0), Sarr (0), 5000000
Call queryperformancecounter (S2)
T1 = (S2-S1)/F
Command2.caption = "time =" & T1
End sub

'----- Traditional VB
Private sub command3_click ()
Dim S1 as currency, S2 as currency
Dim F as currency, T1 as currency
Dim I as long
Call queryperformancefrequency (f) 'timing
Call queryperformancecounter (S1)
For I = 0 to 4999999
Darr (I) = Sarr (I)
Next
Call queryperformancecounter (S2)
T1 = (S2-S1)/F
Command3.caption = "time =" & T1
End sub

Private sub form_load ()

Me. Caption = "supercopymemory VB example"
Dim I as long, J as integer
For I = 0 to ubound (Sarr)
Sarr (I) = J
J = J + 1
If j> 255 then J = 0
Next
Asmini
End sub

All rights reserved by Dan Xin. For reposted content, please indicate the source and notify me

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.