• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Memset() .... Needs to be faster!!!!

## Recommended Posts

Hi all, I use DJGPP C++ DOS compiler and have seen the memset() and memcpy functions and all they are, are just basic string copy functions that copy byte by byte. Can anyone tell me where I can find one that is an assembly memcpy() function or one that can copy data from source to destination much quicker. You see, when I write games, I rely on memcpy() to copy the back buffer to the vga screen and this, I find can be a bit slow. Well, I get a crap frame rate any way. Is there an assembly one that has been already pre-compiled or one for DJGPP that can be linked to my code. Or does anyone know how to write one? if so, do you mind if I have it?? Any help is good help Thanks in advance Dark Star

##### Share on other sites

Just out of my head, hope they are right:

for memset:

mov edi, destination_pointermov eax, value_to_set (0 to 255)mov ecx, number_of_bytes_to_setmov ah, almov ebx, eaxshl eax, 16or eax, ebxshr ecx, 2rep stosd

for memcpy:

mov edi, destination_pointermov esi, source_pointermov ecx, number_of_bytes_to_copyshr ecx, 2rep movsd

Can''t get faster than that. Your source and destination pointers have to be dword aligned, and the number of bytes to set or copy a multiple of 4. If they are not, then just pad your data to fit.

Hope it helps

-AH

##### Share on other sites
Taken from the Unreal Public source - (but anyone could really do this)

MemCopy
mov ecx, Count
mov esi, Src
mov edi, Dest
mov ebx, ecx
shr ecx, 2
and ebx, 3
rep movsd
mov ecx, ebx
rep movsb

(the last part copies all the bytes that do not alight to a dword)

and this is memset(slightly modified)
mov ecx, [Count]
mov edi, [Dest]
mov eax, Value
mov ebx, ecx
shr ecx, 2
and ebx, 3
rep stosd
mov ecx, ebx
rep stosb

But yeah, anaonymous poster you were there... good remembering

Dæmin
(Dominik Grabiec)
sdgrab@eisa.net.au

##### Share on other sites

Dæmin, your memset will not work if you set to a different value than 0x00: say you want to set to 0x12, then eax will be 0x00000012, and the rep stosd will fillup memory with 0000001200000012 (or better 1200000012000000 cause of endian).

- AH

• ### Forum Statistics

• Total Topics
627708
• Total Posts
2978730

• 21
• 14
• 12
• 22
• 35