News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Transferring text from source call to destiny array

Started by LordAdef, March 30, 2025, 06:39:33 AM

Previous topic - Next topic

LordAdef

Hi everyone,

Firstly, my code works!
This post is to check if there is a better way of doing it.

And... because it's actually interesting  :skrewy:

So, How do you do it?
Cheers Alex

the caller:
inv ui_add_button_standard, edi, x, y, 60, 40, chr$("Cancel")

my routine:

ui_add_button_standard proc C uses edi esi parent:DWORD, targ:VARARG
  assume edi:ptr ui_strct_panel
  assume esi:ptr ui_strct_button_standard


here is the code
  ... things
inv lstrlen, targ[16]       ;eax = length of string and loop counter
mov ecx, targ[16]           ;ecx = offset
xor ebx, ebx                ;ebx = pos in target array
mov [esi].text_lenght, eax
@@:
  mov dl, byte ptr [ecx]
  mov [esi].char[ebx], dl
  add ecx, 1
  add ebx, 1
  sub eax, 1
  jnz @B
done:

zedd151

Probably could copy 4 bytes at a time rather than one byte using edx instead of dl?.
Of course you would need to check number of chars remaining, then switch to byte copy if less than 4 chars remaining to copy.
Also, lstrlen probably slower than a self rolled function to do the same job, if speed is needed.
I am away from my computer presently.
¯\_(ツ)_/¯   :azn:

'As we don't do "requests", show us your code first.'  -  hutch—

LordAdef

Quote from: zedd151 on March 30, 2025, 06:47:08 AMProbably could copy 4 bytes at a time rather than one byte using edx instead of dl?.
Of course you would need to check number of chars remaining, then switch to byte copy if less than 4 chars remaining to copy. I am away from my computer presently.
Hi Zedd!

Sure, you are right. But as you already mentioned, there is this overhead of checking sizes.
It's an interesting subject


edit to add:

Inspecting the ch$ MACRO I see this WSTR.
So, instead of filling the LOCAL array, one could use this WSTR to write straight to the destiny array pointer?

zedd151

How long is the string expected to be, that is being copied, longer than a few dwords? Will this be used in many places? If yes to either or both, that may still yield better performance.
Maybe this should be in the Laboratory so the other members can help tweak it into high performance? Or even beat it into submission.  :tongue:
¯\_(ツ)_/¯   :azn:

'As we don't do "requests", show us your code first.'  -  hutch—

LordAdef

Quote from: zedd151 on March 30, 2025, 07:00:34 AMHow long is the string expected to be, that is being copied? Will this be used in many places? If yes to either or both, that may still yield better performance.
Maybe this should be in the Laboratory so the other members can help tweak it into high performance? Or even beat it into submission.  :tongue:
I am never sure where to place posts. But you are again right.


sinsi

I would add one thing
    sub eax, 1
    jnz @B
    mov [esi].char[ebx], al ;<< zero-terminate the destination string
done:
A byte-by-byte copy is fine here since button text is usually not very long :thumbsup:

LordAdef

Quote from: sinsi on March 30, 2025, 07:03:24 AMI would add one thing
    sub eax, 1
    jnz @B
    mov [esi].char[ebx], al ;<< zero-terminate the destination string
done:
A byte-by-byte copy is fine here since button text is usually not very long :thumbsup:
Thanks Sinsi. I was actually, adding the zero termination in my call. But since I am using the length function, I thought that was too much

sinsi

You could also count the string as you copy it, saves a call to lstrlen.