RtlCompareMemory function (wdm.h)

The RtlCompareMemory routine compares two blocks of memory and returns the number of bytes that match until the first difference.


NTSYSAPI SIZE_T RtlCompareMemory(
  [in] const VOID *Source1,
  [in] const VOID *Source2,
  [in] SIZE_T     Length


[in] Source1

A pointer to the first block of memory.

[in] Source2

A pointer to the second block of memory.

[in] Length

The number of bytes to compare.

Return value

RtlCompareMemory returns the number of bytes in the two blocks that match. If all bytes match up to the specified Length value, the Length value is returned.


The routine starts by comparing the first byte in the first block to the first byte in the second block, and continues to compare successive bytes in the two blocks while the bytes match. The routine stops comparing bytes when it encounters the first pair of bytes that are not equal, or when the number of matching bytes equals the Length parameter value, whichever occurs first.

Callers of RtlCompareMemory can be running at any IRQL if both blocks of memory are resident.


Requirement Value
Target Platform Universal
Header wdm.h (include Wdm.h, Ntddk.h, Ntifs.h)
Library NtosKrnl.lib; OneCoreUAP.lib on Windows 10
DLL NtDll.dll (user mode); Kernel32.dll (user mode); NtosKrnl.exe (kernel mode)
IRQL Any level (See Remarks section)
DDI compliance rules BufAfterReqCompletedIntIoctlA(kmdf), BufAfterReqCompletedIoctlA(kmdf), BufAfterReqCompletedReadA(kmdf), BufAfterReqCompletedWriteA(kmdf)