The word has it FillChar is about the fastest way to fill a patch of memory with bytes of the same value (not zero, for that there's ZeroMemory), but is there an equivalent to fill memory with a sequence of the same (four byte) integer or cardinal value? Something like FillInt or FillLongWord?
Asked
Active
Viewed 1,129 times
3
-
3Note that `ZeroMemory` is *not* faster than `FillChar`. Look at the implementation of `ZeroMemory` in Windows.pas to immediately understand why. – Rob Kennedy Jan 21 '10 at 22:11
1 Answers
4
FillDWord is in some Pascal implementations (FreePascal here), don't know if it's in Delphi.
Maybe some simple assembler implementation?
procedure FillDWord( var Destination; Count: Integer; Value: DWord );
assembler; register;
asm
push edi
mov edi, eax // assign Destination
mov eax, ecx // assign Value
mov ecx, edx
rep stosd
pop edi
end;
... or some asm expert could give a better one...
You could also look at the implementation in FreePascal.

Kornel Kisielewicz
- 55,802
- 15
- 111
- 149
-
3FillDWord is defined in the Grids unit in Delphi 2010, and subsequently used once in TCustomGrid.Paint (their implementation is very similar to yours). You can also use FillMemory in the Windows unit if you're okay with using a single byte value, rather than a specific 4-byte value. – Michael Madsen Jan 21 '10 at 22:03
-
I can't figure out a better place than the Grids unit... wait a second, maybe Controls is better... ^_^ – jachguate Jan 22 '10 at 01:31