crc32 with RtlComputeCrc32 (ntdll.dll)

Share your advanced PureBasic knowledge/code with the community.
User avatar
bingo
Enthusiast
Enthusiast
Posts: 210
Joined: Fri Apr 02, 2004 12:21 pm
Location: germany/thueringen
Contact:

crc32 with RtlComputeCrc32 (ntdll.dll)

Post 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:
["1:0>1"]
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

hmmm...nice idea but doesn't work here on my Vista Pc. Unresolved External Symbol - RtlComputeCrc32.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post 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?
User avatar
bingo
Enthusiast
Enthusiast
Posts: 210
Joined: Fri Apr 02, 2004 12:21 pm
Location: germany/thueringen
Contact:

Post 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:
["1:0>1"]
okasvi
Enthusiast
Enthusiast
Posts: 150
Joined: Wed Apr 27, 2005 9:41 pm
Location: Finland

Post 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... :)
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post 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
SPAMINATOR NR.1
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

Highly distracting signature, Rings...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Seldon
Enthusiast
Enthusiast
Posts: 405
Joined: Fri Aug 22, 2003 7:12 am
Location: Italia

Post 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. :)
Post Reply