dcsimg
Page 1 of 2 12 LastLast
Results 1 to 40 of 45

Thread: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2020
    Posts
    239

    Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    i test len("abc")
    Code:
    dim s() as string
    s(i)=******
    
    for i=1 to 10000000***
       len1=lenb(s(i))
    next
    -------------------------------------
    UsedTime(MS):
    AsmLenAbc 1671.9813
    len*2 1932.2963
    lenb 1958.5158
    AsmAbcLong 1980.3853
    GetMem4 2179.2877
    AsmLen 3667.85
    CopyMemory(TLB) 2853.0795
    CopyMemory_lenPtr_(Long)(TLB) 2919.6801
    CopyMemory_LenPtr(Long)(api) 3212.6097
    CopyMemory(API) 3224.7857
    lstrlenWL*2(TLB) 6367.7174
    lstrlenW3*2(API) 5797.746

    New_AsmLenTest.zip
    Name:  PIC_AsmLenTest.jpg
Views: 110
Size:  37.3 KB
    =================
    Code:
    Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
    
    Sub IntAsmABC()
    Dim b(9) As Byte
    b(0) = &H8B
    b(1) = &H44
    b(2) = &H24
    b(3) = &H4
    
    b(4) = &H8B
    b(5) = &H40
    b(6) = &HFC
    
    b(7) = &HC2
    b(8) = &H4
    b(9) = &H0
    
    WriteProcessMemory -1, AddressOf AsmLenAbc, ByVal VarPtr(b(0)), 10, ByVal 0
    WriteProcessMemory -1, AddressOf AsmAbcLong, ByVal VarPtr(b(0)), 10, ByVal 0
    end sub
    
    Function AsmLenAbc(ByVal S As String) As Long   'good
    'Function AsmLenAbc(S As String) As Long 'err
       MsgBox "11"
       MsgBox "22"
       MsgBox "33"
       MsgBox "44"
    End Function
    Function AsmAbcLong(ByVal S As Long) As Long
       MsgBox "11"
       MsgBox "22"
       MsgBox "33"
       MsgBox "44"
    End Function
    
    
    dim s1 as string,StrLenb  as long
    's1 = "中国a"
    s1 = "●●a"
    StrLenb = AsmLenAbc(s1)
    MsgBox "StrLenb=" & StrLenb
    StrLenb = AsmAbcLong(StrPtr(s1)) 'good
    '=======================
    used time log:
    test1c
    UsedTime(MS):
    lenb 998.8594
    len*2 998.4976
    GetMem4 1326.6004
    CopyMemory_lenPtr_(Long)(TLB) 0
    CopyMemory(TLB) 3449.5136
    CopyMemory_LenPtr(Long)(api) 3626.4754
    CopyMemory(API) 3698.5919
    lstrlenWL*2(TLB) 5123.2849
    lstrlenW3*2(API) 6611.2906

    download:StrLen_TEST.zip
    Attachment 174597
    fixed strings no need len(**),The following test doesn't make sense

    lenb 32.0352
    len*2 5901.9404
    GetMem4 13238.1244
    CopyMemory_lenPtr_(Long)(TLB)
    CopyMemory(TLB) 14079.9379
    CopyMemory_LenPtr(Long)(api) 14679.2537
    CopyMemory(API) 14392.8267
    lstrlenWL*2(TLB) 16906.4526
    lstrlenW3*2(API) 17469.9964

    download:StrLen_TEST.zip
    Attachment 174597
    Last edited by xiaoyao; Feb 15th, 2020 at 02:01 PM.

  2. #2
    Fanatic Member
    Join Date
    Feb 2019
    Posts
    522

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    VB6 might be calling SysStringLen/SysStringByteLen to get the string length, which explains the slowness, but it's possible that it's getting the number of bytes directly from the beginning of the string when you use LenB.

  3. #3
    Fanatic Member
    Join Date
    Dec 2014
    Posts
    892

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    not sure what we need to know about calculation of a string length.
    usually what we need is string manipulation and array editing.
    when I work with very large text, its byte array not string at all, since string is slow.
    and working with byte array we already know the length.
    and if I use string I use safearrays. and we can get the length from .cElements1D

    and Im sure most of us are using len/lenb to know the length of a string.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jan 2020
    Posts
    239

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Quote Originally Posted by baka View Post
    not sure what we need to know about calculation of a string length.
    usually what we need is string manipulation and array editing.
    when I work with very large text, its byte array not string at all, since string is slow.
    and working with byte array we already know the length.
    and if I use string I use safearrays. and we can get the length from .cElements1D

    and Im sure most of us are using len/lenb to know the length of a string.
    use string I use safearrays. and we can get the length from .cElements1D

    can you give me a sample project,thank you
    I want to read string from memory
    address by "createfilemapping",
    so it can read or write string from more process。
    The previous method was:write length in 4 byte,write string 。
    need use copymemory api two times.

    if want to read memory,also need call copymemory two times,and
    dim s as string
    s=string(len1," ")
    Required every time data is read Allocating string space

    so I think maybe have a way quick bind memory address to string variable pointer.

  5. #5
    Fanatic Member
    Join Date
    Dec 2014
    Posts
    892

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    do a search, theres plenty of safearray examples in this forum.
    just do a google search: www.vbforums.com safearray

  6. #6

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jan 2020
    Posts
    239

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Quote Originally Posted by baka View Post
    do a search, theres plenty of safearray examples in this forum.
    just do a google search: www.vbforums.com safearray
    I can't open google in china,sorry,can you give me a sample?,thank you

  8. #8

  9. #9
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,574

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Quote Originally Posted by xiaoyao View Post
    i test
    Code:
    dim s() as string
    s(i)=******
    
    for i=1 to 10000000***
       len1=lenb(s(i))
    next
    used time log:

    lenb 32.0352

    len*2 5901.9404
    Most of your postings don't make much sense to me:
    - neither "code-wise" (which is often incomplete, as the above)
    - nor with regards to the english-language
    - nor can I reproduce most of your "test-results"

    Please, you'll have to invest significantly more time, for your posts to "gain any value".
    As they currently are, they're mostly "disturbing gobbledigook"...

    Here's my test-code, which shows only a very, very slight difference between VBs Len- and LenB-function.
    Code:
    Option Explicit
    
    Private Declare Function QueryPerformanceFrequency& Lib "kernel32" (x@)
    Private Declare Function QueryPerformanceCounter& Lib "kernel32" (x@)
    
    Private Sub Form_Click()
      Const Count As Long = 10 ^ 6
      Dim SArr() As String: ReDim SArr(1 To Count) 'allocate 1Mio String-Slots
      
      Dim i As Long, LenRes As Long, T#
      For i = 1 To Count
          SArr(i) = "Some longer Test-String " & i
      Next
      
      T = HPTimer
        For i = 1 To Count
          LenRes = LenB(SArr(i))
        Next
      Caption = LenRes & " " & Format$((HPTimer - T) * 1000, "0.0msec")
    End Sub
     
    Function HPTimer#()
      Dim x@, Frq@
      QueryPerformanceFrequency Frq
      If QueryPerformanceCounter(x) Then HPTimer = x / Frq
    End Function
    And here the results of the above test on my machine (native compiled and in IDE-mode)
    Code:
    LenB (native, all options): 7.4msec (IDE: 33.3msec)
    Len  (native, all options): 7.5msec (IDE: 34.1msec)
    I've not bothered with the APIs which try to find the string-len via "looping until zero char",
    because those are at a disadvantage (compared to BSTRs) already "by definition"...

    Olaf

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jan 2020
    Posts
    239

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Quote Originally Posted by Schmidt View Post
    Most of your postings don't make much sense to me:
    - neither "code-wise" (which is often incomplete, as the above)
    - nor with regards to the english-language
    - nor can I reproduce most of your "test-results"

    Please, you'll have to invest significantly more time, for your posts to "gain any value".
    As they currently are, they're mostly "disturbing gobbledigook"...

    Here's my test-code, which shows only a very, very slight difference between VBs Len- and LenB-function.
    Code:
    Option Explicit
    
    Private Declare Function QueryPerformanceFrequency& Lib "kernel32" (x@)
    Private Declare Function QueryPerformanceCounter& Lib "kernel32" (x@)
    
    Private Sub Form_Click()
      Const Count As Long = 10 ^ 6
      Dim SArr() As String: ReDim SArr(1 To Count) 'allocate 1Mio String-Slots
      
      Dim i As Long, LenRes As Long, T#
      For i = 1 To Count
          SArr(i) = "Some longer Test-String " & i
      Next
      
      T = HPTimer
        For i = 1 To Count
          LenRes = LenB(SArr(i))
        Next
      Caption = LenRes & " " & Format$((HPTimer - T) * 1000, "0.0msec")
    End Sub
     
    Function HPTimer#()
      Dim x@, Frq@
      QueryPerformanceFrequency Frq
      If QueryPerformanceCounter(x) Then HPTimer = x / Frq
    End Function
    And here the results of the above test on my machine (native compiled and in IDE-mode)
    Code:
    LenB (native, all options): 7.4msec (IDE: 33.3msec)
    Len  (native, all options): 7.5msec (IDE: 34.1msec)
    I've not bothered with the APIs which try to find the string-len via "looping until zero char",
    because those are at a disadvantage (compared to BSTRs) already "by definition"...

    Olaf
    Code:
    '============== test1.exe
    'Dim TempStrArr() As String
    's1 = String(60, "a")
    'ReDim TempStrArr(C)
    'For I = 1 To C
    '    TempStrArr(I) = "STR" & I & s1
    'Next
    '============== 'test2.exe
    Dim TempStrArr() As String * 70
    ReDim TempStrArr(C)
    For I = 1 To C
        TempStrArr(I) = "STR" & I
    Next
    i used Dim TempStrArr() As String * 70
    so len mayby not work normal?

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jan 2020
    Posts
    239

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    it's my sample,you can try
    download:
    StrLen_TEST.zip

  12. #12
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,574

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Quote Originally Posted by xiaoyao View Post
    Code:
    Dim TempStrArr() As String * 70
    ReDim TempStrArr(C)
    For I = 1 To C
        TempStrArr(I) = "STR" & I
    Next
    i used Dim TempStrArr() As String * 70
    so len mayby not work normal?
    In case of fixed strings, it does not make all that much sense, to call the Len, or LenB-functions,
    because they will always return the "fixed size, used in the String-Definition"...

    For your example above that means, that:
    - Len(...) will always return 70
    - LenB(...) will always return 140
    for all the different content in your (fixed-String)-Array-Members.

    Olaf

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Jan 2020
    Posts
    239

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Quote Originally Posted by Schmidt View Post
    In case of fixed strings, it does not make all that much sense, to call the Len, or LenB-functions,
    because they will always return the "fixed size, used in the String-Definition"...

    For your example above that means, that:
    - Len(...) will always return 70
    - LenB(...) will always return 140
    for all the different content in your (fixed-String)-Array-Members.

    Olaf
    how to quickly copy string to memory address ?
    like this :
    dim str1 as dting
    str1="abc"
    call put_str_to_address(336525,str1)
    or put_str_to_address 336525,"abc"
    use api or asmcode?
    which is The fastest way?

  14. #14
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,574

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Quote Originally Posted by xiaoyao View Post
    how to quickly copy string to memory address ?
    ...
    which is The fastest way?
    Experienced developers don't care about "the fastest way" -
    (at least not in the beginning of a project, or a larger implementation-part).

    Please make yourself familiar with this article here first:
    http://wiki.c2.com/?PrematureOptimization
    (which offers a lot of sub-links to other "keywords and phrases" a developer should be familiar with).

    In short:
    Without knowing about your context, your plans for your current project, or how "everything you wrote so far" interacts,
    there is no good answer to any "performance-optimization-question".

    Maybe these String-copying-parts are not the bottleneck in your App, ...who knows?
    Maybe you don't even need "Strings" at all (for these specific parts), ...who knows?

    So, it's more important first, to think about:
    - better design (better structuring)
    - not "repeating yourself" (DRY principle)
    - not overcomplicating things without need (KISS-principle)
    - choosing the right DataContainer-(or List-)Classes for the given situation (Arrays, Collections, Dictionaries, Recordsets)
    - also, which code-parts to leave in *.bas-modules - using "structs" (UDTs)
    - which code-parts to better move into Classes
    - good interface-design of those Classes (naming + arranging of Methods and Arguments)
    - identifying the "generic (commonly usable) parts" of your Project
    - along with: "making currently specific parts generically usable"
    - followed by "moving these generic, rarely changing parts" out of the Main-Project, into Dll-Projects

    All these things come "before any performance-optimizations"
    (and before any "threading-questions", which are almost always performance-related as well).

    So, do you have a concrete Project which does "something useful" to show (the one which does have "the performance-problem")?
    If yes, did you do "your homework on it" already (according to what I've just listed above)?

    If you did (and there's still a "performance-problem"),
    you should be able to upload the project in question for code- (and performance-) review...

    Olaf

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Jan 2020
    Posts
    239

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    It took 4 seconds at the beginning. Now with a good method, it takes only one second and the speed is increased by 3 times. This ending is still very good. Optimization has not been wasted.
    For vb6, an IDE programming tool developed 22 years ago, proper optimization is still necessary.
    After all, I just developed some small engineering software by myself, which is basically enough, solve some problems, increase speed, and optimize it.
    chinese:刚开始需要4秒钟时间,用了好的方法现在只要一秒钟,速度提高了3倍,这个结局还是很好的,优化并没有白费功夫。
    对于vb6这个22年前开发的ide编程工具,适当的优化还是很有必要。
    毕竟只是自己开发一些小工程软件,基本够用了,解决一些难题,把速度提高上去,优化一下已经非常好了。

  16. #16
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,574

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Quote Originally Posted by xiaoyao View Post
    It took 4 seconds at the beginning.
    Now, if only we knew, what exactly took 4 seconds in the beginning... (meaning: please post code).

    Quote Originally Posted by xiaoyao View Post
    Now with a good method, it takes only one second and the speed is increased by 3 times.
    Your math-skills are "somewhat off", because I'd think that this would be a speed-increase of factor 4 (not 3).

    And as said above, unless you post concrete code, we cannot know if you're "just making things up".

    Quote Originally Posted by xiaoyao View Post
    For vb6, an IDE programming tool developed 22 years ago, proper optimization is still necessary.
    No - not "generally" - absolutely not.
    The link I gave about "premature optimization" is an universal truth, independent of the used programming-language.

    Besides, the C2.exe (native VC++ version 6) compiler in VB6 is still good enough, to write implementations -
    which show better performance than MS-implementations which ship with a current Win10
    (and are compiled with a VC++ compiler, several generations younger than C2.exe).

    Olaf

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Jan 2020
    Posts
    239

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Now,i use asmcode it's quickly than "lenb","len*2" by asm code
    last time ,i tes asmabc(s) like lenb(s),used 155ms,by "CopyMemory" used 1770 ms
    the first time ,i read,write string to "CreateFileMapping",when read string,Need read length first by "copymemory"
    '=============
    UsedTime(MS):
    AsmABC 155.513
    len*2 179.6245
    lenb 231.1023
    AsmAbcLong 256.4215
    AsmLen 307.6093
    GetMem4 333.6848
    CopyMemory_lenPtr_(Long)(TLB) 1180.0676
    CopyMemory(TLB) 1184.1642
    CopyMemory_LenPtr(Long)(api) 1726.6629
    CopyMemory(API) 1770.2149
    lstrlenWL*2(TLB) 4693.9242
    lstrlenW3*2(API) 4671.7401
    '=============
    AsmLenAbc 1671.9813
    len*2 1932.2963
    lenb 1958.5158
    AsmAbcLong 1980.3853
    GetMem4 2179.2877
    AsmLen 3667.85
    CopyMemory(TLB) 2853.0795
    CopyMemory_lenPtr_(Long)(TLB) 2919.6801
    CopyMemory_LenPtr(Long)(api) 3212.6097
    CopyMemory(API) 3224.7857

  18. #18
    Frenzied Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    1,720

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    JFYI, Len is implemented in ASM as LenB / 2 so it cannot possibly be faster than LenB. I'm positive your benchmarking code is flawed as it's not easy to micro-benchmark functions that are implemented in 5-6 CPU instructions.

    Just prevent a single string allocation and you gain about 1000 LenB invokations for free. The "Premature optimization" topic is all about optimizing the wrong part of the code -- string allocations vs LenB calls.

    cheers,
    </wqw>

  19. #19
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,574

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Quote Originally Posted by xiaoyao View Post
    Now,i use asmcode it's quickly than "lenb","len*2" by asm code
    last time ,i tes asmabc(s) like lenb(s),used 155ms,by "CopyMemory" used 1770 ms
    the first time ,i read,write string to "CreateFileMapping",when read string,Need read length first by "copymemory"
    There's still no "useful information" in your postings (it's still "mostly gibberish" - without any context).

    If you want help from us:
    - please provide decent context-information
    - ideally in form of a zipped "real-world-VB6-project" (which does something useful)
    - and not some premature performance-tests which make no sense at all

    What do you really want to do?

    Olaf

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Jan 2020
    Posts
    239

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Quote Originally Posted by Schmidt View Post
    There's still no "useful information" in your postings (it's still "mostly gibberish" - without any context).

    If you want help from us:
    - please provide decent context-information
    - ideally in form of a zipped "real-world-VB6-project" (which does something useful)
    - and not some premature performance-tests which make no sense at all

    What do you really want to do?

    Olaf
    This function I am mainly used to copy the binding of memory addresses and string variables. Do a memory file mapping, and then different processes can directly access memory by using string name variables. Here, the safe array and pointer methods are used.
    chinese:这个功能我现在主要用于拷贝内存地址和字符串变量的绑定。搞一个内存文件映射,然后不同的进程可以直接用字符串名变量的方式直接访问内存,这里使用了安全数组和指针的方法。
    how to read string from memory by pointer for CreateFileMapping?
    http://www.vbforums.com/showthread.p...ateFileMapping
    dim ptrstr1 as string '* ptr
    dim lenarr() as long '* ptr
    dim strarr() as long *100 '* ptr +4
    so I can use:
    write string:
    lenarr(0)=lenb(s)
    strrarr(0)=s

    readstring from filemapping(memory):
    msgbox ptrstr1

    it's a way to read/write memory without api calling for run quickly。
    it's used for share variable to more process.
    write abc.exe "dim ptrstr1 as string",read from abc2.exe by ptrstr1。
    Just as multiple threads can access global variables in a process, we now implement global variables for multiple processes. .

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Jan 2020
    Posts
    239

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Quote Originally Posted by Schmidt View Post
    There's still no "useful information" in your postings (it's still "mostly gibberish" - without any context).

    If you want help from us:
    - please provide decent context-information
    - ideally in form of a zipped "real-world-VB6-project" (which does something useful)
    - and not some premature performance-tests which make no sense at all

    What do you really want to do?

    Olaf
    This function I am mainly used to copy the binding of memory addresses and string variables. Do a memory file mapping, and then different processes can directly access memory by using string name variables. Here, the safe array and pointer methods are used.
    chinese:这个功能我现在主要用于拷贝内存地址和字符串变量的绑定。搞一个内存文件映射,然后不同的进程可以直接用字符串名变量的方式直接访问内存,这里使用了安全数组和指针的方法。
    how to read string from memory by pointer for CreateFileMapping?
    http://www.vbforums.com/showthread.p...ateFileMapping
    dim ptrstr1 as string '* ptr
    dim lenarr() as long '* ptr
    dim strarr() as long *100 '* ptr +4
    so I can use:
    write string:
    lenarr(0)=lenb(s)
    strrarr(0)=s

    readstring from filemapping(memory):
    msgbox ptrstr1

    it's a way to read/write memory without api calling for run quickly。
    it's used for share variable to more process.
    write abc.exe "dim ptrstr1 as string",read from abc2.exe by ptrstr1。
    Just as multiple threads can access global variables in a process, we now implement global variables for multiple processes. .

  22. #22

    Thread Starter
    Addicted Member
    Join Date
    Jan 2020
    Posts
    239

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Multi-threading can access all global variables in the software, including forms, objects, and controls.
    Now I am sharing all the variables between multiple processes, if I can share the variables between multiple computers.
    It's a bit like an in-memory database(mongo).
    chinese:多线程可以访问软件里面的所有全局变量,包括窗体还有对象,控件。
    现在我是把多个进程之间的变量全部共享了,如果可以把多台电脑之间也可以共享变量。
    有点像是内存数据库的味道(mongo)。
    Last edited by xiaoyao; Feb 15th, 2020 at 10:00 PM.

  23. #23
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,574

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Quote Originally Posted by xiaoyao View Post
    it's a way to read/write memory without api calling for run quickly。
    it's used for share variable to more process.
    write abc.exe "dim ptrstr1 as string",read from abc2.exe by ptrstr1。
    Still not making any sense, as far as the "discussion" here goes...

    Hmm, so far I've thought "over-eager chinese teenager, fighting the language barrier"...

    In the meantime I begin to think "bot":
    - with instructions to gather context from the thread-title and previous postings
    - occasionally throwing in a link (according to and roughly matching that gathered context)
    - followed by a mix of auto-translated chinese and english gobbledigook
    . (tuned a bit, to "sound like nerd-speak", mixed with keywords of the given context)

    The only thing which throws me off a bit from that theory, are those occasionally thrown in Zip-Files, which contain VB6-Code.
    But those might have been copied from "some place else" - being pre-analyzed and categorized as well
    (to throw them in, when the context of the discussion-threads here roughly matches the pre-analyzed zip-category).

    What's your opinion on that?

    Olaf

  24. #24

    Thread Starter
    Addicted Member
    Join Date
    Jan 2020
    Posts
    239

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Quote Originally Posted by Schmidt View Post
    Still not making any sense, as far as the "discussion" here goes...

    Hmm, so far I've thought "over-eager chinese teenager, fighting the language barrier"...

    In the meantime I begin to think "bot":
    - with instructions to gather context from the thread-title and previous postings
    - occasionally throwing in a link (according to and roughly matching that gathered context)
    - followed by a mix of auto-translated chinese and english gobbledigook
    . (tuned a bit, to "sound like nerd-speak", mixed with keywords of the given context)

    The only thing which throws me off a bit from that theory, are those occasionally thrown in Zip-Files, which contain VB6-Code.
    But those might have been copied from "some place else" - being pre-analyzed and categorized as well
    (to throw them in, when the context of the discussion-threads here roughly matches the pre-analyzed zip-category).

    What's your opinion on that?

    Olaf
    Don't be ridiculous, we are just discussing technical issues. You're still here to suspect that I am a robot. What else? I did n’t think I sent the password, but it may be correct. It was copied from somewhere else. You have a big brain.

  25. #25
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,838

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Quote Originally Posted by xiaoyao View Post
    Multi-threading can access all global variables in the software, including forms, objects, and controls.
    Now I am sharing all the variables between multiple processes, if I can share the variables between multiple computers.
    It's a bit like an in-memory database(mongo).
    chinese:多线程可以访问软件里面的所有全局变量,包括窗体还有对象,控件。
    现在我是把多个进程之间的变量全部共享了,如果可以把多台电脑之间也可以共享变量。
    有点像是内存数据库的味道(mongo)。
    Hi xiaoyao, you should simplify the project you want to do into a small and complete test project and clearly state what you want to achieve. In this way, others can propose various improvement or optimization solutions according to the actual situation. Otherwise, you are wasting both your time and others' time.

  26. #26

    Thread Starter
    Addicted Member
    Join Date
    Jan 2020
    Posts
    239

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Just kidding, I don't comment too much on others. Everyone asks a question, there will always be his needs or ideas. It's possible that this idea is bad and not very practical. Just like some people think that vb does not need multi-threading at all, but I think it is very important and necessary. Green vegetables and radish have their own love. Let us return to the subject. What's the fastest way to copy a string to a memory address, including the first 4 bytes in length.
    chinese:只是开个玩笑,我也不会过多的去评论别人。每个人提出问题,总会有他的需要或者想法。有可能这个想法比较糟糕,不太实用。就像有的人认为vb根本就不需要多线程,但是我觉得还是很重要的,必不可少 ,青菜萝卜各有所爱嘛。还是让我们回到正题上来吧。有什么最快的方法,把字符串复制到一个内存地址,包括前面的4个字节长度。

  27. #27
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,838

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Quote Originally Posted by xiaoyao View Post
    Just kidding, I don't comment too much on others. Everyone asks a question, there will always be his needs or ideas. It's possible that this idea is bad and not very practical. Just like some people think that vb does not need multi-threading at all, but I think it is very important and necessary. Green vegetables and radish have their own love. Let us return to the subject. What's the fastest way to copy a string to a memory address, including the first 4 bytes in length.
    chinese:只是开个玩笑,我也不会过多的去评论别人。每个人提出问题,总会有他的需要或者想法。有可能这个想法比较糟糕,不太实用。就像有的人认为vb根本就不需要多线程,但是我觉得还是很重要的,必不可少 ,青菜萝卜各有所爱嘛。还是让我们回到正题上来吧。有什么最快的方法,把字符串复制到一个内存地址,包括前面的4个字节长度。
    Then you should ask this question like this:

    How to copy a string to a memory address in the fastest way, including the first 4 bytes.
    Or
    Copy a string to a memory address in the fastest way, including the first 4 bytes.

    You should learn how to ask your question concisely and clearly.

  28. #28

    Thread Starter
    Addicted Member
    Join Date
    Jan 2020
    Posts
    239

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    how to read string from memory by pointer for CreateFileMapping?

    http://www.vbforums.com/showthread.p...ateFileMapping
    My main purpose is another post, how to share data between multiple processes, and bind memory addresses directly by string variables. So it involves reading the length of the string and then copying the data over (length + 4). The easiest way is to use API RtlMoveMemory, this is a waste of time.
    I always think there should be a better way. For example, copying a section of memory using assembly is as simple as that. If you use vc ++, it may be solved in a few seconds, but vb6 does not support modifying the pointer, so you must use a lot of strange methods.
    In short, it is how the assembly implements string copy (asm strcopy)
    chinese:
    我的主要用途就是另外一个帖子,如何多个进程之间共享数据,用字符串变量的方式绑定内存地址直接读写。所以这里涉及到读取字符串的长度,然后复制数据过去(长度+4)。最简单的方法就是用API RtlMoveMemory,这个比较浪费时间。
    我总是认为应该有一种更好的方法。比如用汇编复制一段内存,就这么简单的一件事情。如果用vc++,可能几秒钟就解决了,只是vb6不支持修改指针,所以要用不少的奇怪方法。
    简单说就是汇编如何实现字符串复制 (asm strcopy)

  29. #29

  30. #30

    Thread Starter
    Addicted Member
    Join Date
    Jan 2020
    Posts
    239

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Quote Originally Posted by dreammanor View Post
    Then you should ask this question like this:

    How to copy a string to a memory address in the fastest way, including the first 4 bytes.
    Or
    Copy a string to a memory address in the fastest way, including the first 4 bytes.

    You should learn how to ask your question concisely and clearly.
    thanks about your advice.
    Sorry, my English is not very good. Reading the length of a string is just one function inside. The ultimate goal is that I still want to be able to share string arrays or structure variables. Structure arrays are shared by memory so that multiple processes can read these information at the same time. Reading is simple. I just want to make it run faster and more efficiently. For example, if I want to read out a string, the ordinary method needs to dynamically allocate string space every time, read the length and copy it in.
    With a good method, reading and writing to shared memory data does not need to call any api.
    chinese:我使用自动翻译软件,所以很多意义可能表达不清楚,所以我会把中文同时发上来,你们可以用翻译软件把中文翻译成英文。
    对不起,我的英文不太好。读取字符串长度只是里面的一个功能。最终目标我还是希望能够把字符串数组或者结构变量,结构数组通过内存共享,让多个进程可以同时读取这些信息,读取很简单我只是希望能够让他运行更快,效 率更高。比如我要把字符串读出来,普通方法需要每次动态分配字符串空间,读取长度再拷贝进去。用了好的方法,读取写入共享内存数据就不需要调用任何api。

  31. #31

    Thread Starter
    Addicted Member
    Join Date
    Jan 2020
    Posts
    239

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Quote Originally Posted by The trick View Post
    xiaoyao, why do you want to copy a string? What's the end goal? Maybe it's faster to make no copy?
    it's like a memory database for more process read/write,(mongo).
    type fields
    id as long
    name as string
    date1 as date
    'more fields
    end type
    public RowData(rows=100) as fields
    'it's like a table

  32. #32
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,838

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Quote Originally Posted by xiaoyao View Post
    thanks about your advice.
    Sorry, my English is not very good. Reading the length of a string is just one function inside. The ultimate goal is that I still want to be able to share string arrays or structure variables. Structure arrays are shared by memory so that multiple processes can read these information at the same time. Reading is simple. I just want to make it run faster and more efficiently. For example, if I want to read out a string, the ordinary method needs to dynamically allocate string space every time, read the length and copy it in.
    With a good method, reading and writing to shared memory data does not need to call any api.
    chinese:我使用自动翻译软件,所以很多意义可能表达不清楚,所以我会把中文同时发上来,你们可以用翻译软件把中文翻译成英文。
    对不起,我的英文不太好。读取字符串长度只是里面的一个功能。最终目标我还是希望能够把字符串数组或者结构变量,结构数组通过内存共享,让多个进程可以同时读取这些信息,读取很简单我只是希望能够让他运行更快,效 率更高。比如我要把字符串读出来,普通方法需要每次动态分配字符串空间,读取长度再拷贝进去。用了好的方法,读取写入共享内存数据就不需要调用任何api。
    You see, Olaf and The trick ask you similar questions. That's why I advise you in post #25.

    In addition, there are three people who can solve your problem perfectly: Olaf, wqweto and The trick.

  33. #33
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,838

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Quote Originally Posted by xiaoyao View Post
    it's like a memory database for more process read/write,(mongo).
    type fields
    id as long
    name as string
    date1 as date
    'more fields
    end type
    public RowData(rows=100) as fields
    'it's like a table
    Maybe you should learn about SqliteDB's in-memory database mode

  34. #34

    Thread Starter
    Addicted Member
    Join Date
    Jan 2020
    Posts
    239

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Quote Originally Posted by dreammanor View Post
    Maybe you should learn about SqliteDB's in-memory database mode
    In fact, I don't need to be so complicated, I just want to be able to read strings or string arrays, structures, arrays of structures, and that's it.
    It is to bind my variables and memory addresses, and directly use variables to read and write memory data.
    chinese:其实我也不需要那么复杂,只希望能够读取字符串或者字符串数组,结构,结构数组,这样就可以了。
    就是把我的这些变量和内存地址绑定起来,直接用变量就可以读写内存数据。

  35. #35
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,838

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    It seems that you haven't replied Olaf and The trick's comments.

  36. #36
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,173

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    >What's your opinion on that?

    223 posts since 23 Jan none of which has made much sense, it is spam. Time to stop it perhaps?

  37. #37

    Thread Starter
    Addicted Member
    Join Date
    Jan 2020
    Posts
    239

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Quote Originally Posted by The trick View Post
    xiaoyao, why do you want to copy a string? What's the end goal? Maybe it's faster to make no copy?
    Maybe it's faster to make no copy?yes
    my code put length to memory address(1-4)
    write string:
    Code:
    lenarr(0)=lenb(s) 'write byte 1-4
    strrarr(0)=s           'write string to memory(5-?)
    I used two safearry pointer
    need two lines code,how to chang for asm code?
    sub asm_putstr(byval s1 as string,memory_address as long)
    'asm code
    end sub
    Last edited by xiaoyao; Feb 16th, 2020 at 05:49 AM.

  38. #38
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    2,015

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Quote Originally Posted by Schmidt View Post
    In the meantime I begin to think "bot":
    I just wonder whether it is programmed in VB6 or in some other language...

  39. #39

    Thread Starter
    Addicted Member
    Join Date
    Jan 2020
    Posts
    239

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Quote Originally Posted by Eduardo- View Post
    I just wonder whether it is programmed in VB6 or in some other language...
    maybe he use vc++,c#
    it's support pointer ,for variable bind to memory address.
    vb6 not support pointer,so it's hard。
    vb6 support part of safearry ,50% performance loss.
    like
    Code:
    for I=1 to 1000000*
        a=i       'used 10s 
        b(i)=i   'used 15s
    next

  40. #40
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,574

    Re: Running speed test-len/lenb/lstrlenW/CopyMemory/GetMem4

    Quote Originally Posted by xiaoyao View Post
    maybe he use vc++,c#
    it's support pointer ,for variable bind to memory address.
    vb6 not support pointer,so it's hard。
    vb6 support part of safearry ,50% performance loss.
    like
    Code:
    for I=1 to 1000000*
        a=i       'used 10s 
        b(i)=i   'used 15s
    next
    This is just another example of not understanding (or correctly interpreting)
    the previous posting...

    And it was also already said, that performance is relative.

    You don't need to bring down a routine from 200nano-seconds to e.g. 50nano-seconds,
    when it's part of a "one-time-UI-action" (e.g. caused by a Click-Event).

    The user will not notice such a "factor 4" improvement at all.

    So again, without putting your efforts into a decent context (into concrete code,
    which does something useful - and not just runs "synthetic test-loops"),
    all of your current tests are completely pointless.

    To give an example...
    You could test your "theories and code for fast(er) String-Processing in VB6",
    by implementing something concrete, e.g. like a "fast Word-scanner/analyzer",
    with the task:
    - to use the "works of Shakespeare" as input (all in a single file '100.txt', download here: http://vbRichClient.com/Downloads/100.zip)
    - then go through (enumerate) each word of this file
    - filling an internal "List of unique words"
    - increasing an internal Counter on each of these words in your internal "unique Word-List"
    - then presenting the Results (the list of unique words - and their counts) in a GUI-control
    - along with the final "over-all-timing"

    That's an example for a concrete (non-synthetic) task, which "stresses String-Processing"
    (in a quite common "real-world-like pattern" - parsing larger text-input ... and presenting the "processed results" to the user).

    You could engage that problem even in multiple threads (or multiple processes),
    to "bring down the final timing till presentation in the GUI".

    Please show us in a concrete implementation, that all your "new won insights, how to make VB6 faster" are really worth our while.

    Olaf

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width