The following is a small and fast memfill routine. It is aimed at memory
that is allocated in uninitialised form that needs to be initialised
quickly. It also works on string memory with the correct address.
It writes in DWORD size so the length will need to be a multiple of four
but this is generally not difficult to do as a buffer that is a multiple
of four aligns better. If the length is not a multiple of four, it will
miss the last bytes above the last multiple of four.
The parameters in PowerBASIC are as follows,
1. lpmem an address provided by functions like VarPtr, StrPtr or a function
return value that is an address.
2. ln is the byte length of the buffer.
3. fill this would normally be 0 but a DWORD size variable can be filled
with any 4 characters as follows.
LOCAL var as DWORD
! mov eax, " " ; 4 spaces
! mov var, eax
then use var as the last parameter.
Clocks up on my PIII at about 190 meg/sec so it should be fast enough for
most applications.
Regards,
[email protected]
------------------
that is allocated in uninitialised form that needs to be initialised
quickly. It also works on string memory with the correct address.
It writes in DWORD size so the length will need to be a multiple of four
but this is generally not difficult to do as a buffer that is a multiple
of four aligns better. If the length is not a multiple of four, it will
miss the last bytes above the last multiple of four.
The parameters in PowerBASIC are as follows,
1. lpmem an address provided by functions like VarPtr, StrPtr or a function
return value that is an address.
2. ln is the byte length of the buffer.
3. fill this would normally be 0 but a DWORD size variable can be filled
with any 4 characters as follows.
LOCAL var as DWORD
! mov eax, " " ; 4 spaces
! mov var, eax
then use var as the last parameter.
Clocks up on my PIII at about 190 meg/sec so it should be fast enough for
most applications.
Regards,
[email protected]
Code:
' ######################################################################### SUB memfill(ByVal lpmem as DWORD,ByVal ln as DWORD,ByVal fill as DWORD) #REGISTER NONE ! mov ecx, ln ; byte length ! mov eax, fill ; fill chars ! mov edx, lpmem ; buffer address ! add ecx, edx ; offset for exit condition memSt: ! mov [edx], eax ; put fill chars at address in edx ! add edx, 4 ; increment edx by 4 (DWORD) ! cmp edx, ecx ; compare to counter ! jbe memSt ; jump if below or equal END SUB ' #########################################################################