L
Lance
Hi all,
I'm curious as to the technicalities of why a particular method declaring and calling is
faster than the other. The C syntax is:
\\\\\
BOOL PathMatchSpec(
LPCSTR pszFile,
LPCSTR pszSpec
);
\\\\\
In VB2005, I'm declaring and then calling an API function as such:
\\\\\
Private Declare Auto Function PathMatchSpec Lib "shlwapi" _
(ByVal pszFileParam As IntPtr, _
ByVal pszSpec As IntPtr) As Boolean
Private Function MatchSpec(ByVal sFile As String, ByVal sSpec As String) As Boolean
Dim FilePtr As IntPtr = Marshal.StringToHGlobalAuto(sFile)
Dim SpecPtr As IntPtr = Marshal.StringToHGlobalAuto(sSpec)
Dim Match As Boolean
Match = PathMatchSpec(FilePtr, SpecPtr)
Marshal.FreeHGlobal(FilePtr)
Marshal.FreeHGlobal(SpecPtr)
Return Match
End Function
\\\\\
This (the above example) runs nearly 20% faster over the course of about 190,000 calls
than declaring and calling it as such:
\\\\\
Private Declare Auto Function PathMatchSpec Lib "shlwapi" _
(ByVal pszFileParam As String, _
ByVal pszSpec As String) As Boolean
Private Function MatchSpec(ByVal sFile As String, ByVal sSpec As String) As Boolean
Return PathMatchSpec(sFile, sSpec)
End Function
\\\\\
With all the marshaling in the first example, I would have thought there would have been
some significant overhead going on compared to the second example.
I'm curious as to the technicalities of why a particular method declaring and calling is
faster than the other. The C syntax is:
\\\\\
BOOL PathMatchSpec(
LPCSTR pszFile,
LPCSTR pszSpec
);
\\\\\
In VB2005, I'm declaring and then calling an API function as such:
\\\\\
Private Declare Auto Function PathMatchSpec Lib "shlwapi" _
(ByVal pszFileParam As IntPtr, _
ByVal pszSpec As IntPtr) As Boolean
Private Function MatchSpec(ByVal sFile As String, ByVal sSpec As String) As Boolean
Dim FilePtr As IntPtr = Marshal.StringToHGlobalAuto(sFile)
Dim SpecPtr As IntPtr = Marshal.StringToHGlobalAuto(sSpec)
Dim Match As Boolean
Match = PathMatchSpec(FilePtr, SpecPtr)
Marshal.FreeHGlobal(FilePtr)
Marshal.FreeHGlobal(SpecPtr)
Return Match
End Function
\\\\\
This (the above example) runs nearly 20% faster over the course of about 190,000 calls
than declaring and calling it as such:
\\\\\
Private Declare Auto Function PathMatchSpec Lib "shlwapi" _
(ByVal pszFileParam As String, _
ByVal pszSpec As String) As Boolean
Private Function MatchSpec(ByVal sFile As String, ByVal sSpec As String) As Boolean
Return PathMatchSpec(sFile, sSpec)
End Function
\\\\\
With all the marshaling in the first example, I would have thought there would have been
some significant overhead going on compared to the second example.