Page 1 of 1

crc32 with RtlComputeCrc32 (ntdll.dll)

Posted: Thu Mar 15, 2007 10:59 am
by bingo

Code: Select all

Import "ntdll.lib"
RtlComputeCrc32(dwInitial.l,pData.l,iLen.l)
EndImport

buffer.s = "1234567" + Space(512) + "1234567"
lenbuffer.l = Len(buffer)

counter.l = 999999

For s=1 To 3

timer = GetTickCount_()
For i=1 To counter
CRC32Fingerprint(@buffer,lenbuffer) 
Next
Debug "pb... " + Str(GetTickCount_() - timer)
Debug Hex(CRC32Fingerprint(@buffer,lenbuffer))

timer = GetTickCount_()
For i=1 To counter
RtlComputeCrc32(0,@buffer,lenbuffer)
Next
Debug "api..." + Str(GetTickCount_() - timer)
Debug Hex(RtlComputeCrc32(0,@buffer,lenbuffer))

Next
my xp pc:

pb... 1860
D359D67E
api...1484
D359D67E
pb... 1844
D359D67E
api...1484
D359D67E
pb... 1828
D359D67E
api...1485
D359D67E

my vista pc:

pb... 2247
D359D67E
api...1903
D359D67E
pb... 2199
D359D67E
api...1857
D359D67E
pb... 2215
D359D67E
api...1872
D359D67E

RtlComputeCrc32 15-20% faster as CRC32Fingerprint ?

:shock:

Posted: Thu Mar 15, 2007 1:20 pm
by SFSxOI
hmmm...nice idea but doesn't work here on my Vista Pc. Unresolved External Symbol - RtlComputeCrc32.

Posted: Thu Mar 15, 2007 1:43 pm
by Rescator
That function is not in the PSDK, also ntdll is not documented "officially".
I would not rely on anything in it as it could change from Windows release/build to the next.

PS! The reason it is faster is that it most likely use file memory mapping,
not to mention being on a kernel level I think?

Posted: Thu Mar 15, 2007 1:47 pm
by bingo
RtlComputeCrc32 is not in pb-standard ntdll.lib ! create a new or use http://kyf.net/tmp/ntdll.zip and it works ... :lol:

Posted: Mon Mar 19, 2007 1:56 pm
by okasvi
bingo wrote:RtlComputeCrc32 is not in pb-standard ntdll.lib ! create a new or use http://kyf.net/tmp/ntdll.zip and it works ... :lol:
or just use LoadLibrary/GetProcAddress... :)

Posted: Mon Mar 19, 2007 2:33 pm
by Rings
Did not work with w2k, works with win-xp
here is a more friendly version:

Code: Select all

LibName.s="ntdll.dll"
FuncName.s="RtlComputeCrc32"

Prototype PrototypeRtlComputeCrc32(dwInitial.l,pData.l,iLen.l)

LibNR=LoadLibrary_(Libname)
If LibNR
 FuncPointer=GetProcAddress_(LibNR,FuncName)
 If FuncPointer
  RtlComputeCrc32.PrototypeRtlComputeCrc32=FuncPointer 
  buffer.s = "1234567" + Space(512) + "1234567"
  lenbuffer.l = Len(buffer)
  counter.l = 999999
  For s=1 To 3
   timer = GetTickCount_()
   For i=1 To counter
    CRC32Fingerprint(@buffer,lenbuffer)
   Next
   Debug "pb... " + Str(GetTickCount_() - timer)
   Debug Hex(CRC32Fingerprint(@buffer,lenbuffer))
   timer = GetTickCount_()
   For i=1 To counter
    RtlComputeCrc32(0,@buffer,lenbuffer)
   Next
   Debug "api..." + Str(GetTickCount_() - timer)
   Debug Hex(RtlComputeCrc32(0,@buffer,lenbuffer))
  Next
 Else
  Debug "Cannot find entrypoint for " + Funcname
 EndIf
 FreeLibrary_(LibNR)
Else
  Debug "Cannot open library " + Libname
EndIf

Posted: Mon Mar 19, 2007 3:02 pm
by blueznl
Highly distracting signature, Rings...

Posted: Fri Mar 23, 2007 9:44 am
by Seldon
Hi ! What are the specs for the Vista PC ? I hope it is slower than the one with XP because of a slower CPU and not for the OS. :)