[fpc-devel] Is calling the Windows Unicode APIs really faster than the ANSI API's?

Ivo Steinmann ivo_steinmann at gmx.net
Fri Sep 26 11:19:59 CEST 2008


Ivo Steinmann schrieb:
>
> In the core of all windows nt systems, there's the NT API. The normal
> WinAPI is on the top of the NTAPI. the NT API itself uses UTF-16 as
> stringtype!
>
> type
>   UNICODE_STRING = record
>     Length: USHORT;
>     MaximumLength: USHORT;
>     Buffer: PWSTR;
>   end;
>
> const
>   FileShareMode = FILE_SHARE_READ or FILE_SHARE_WRITE or FILE_SHARE_DELETE;
> var
>   str: UNICODE_STRING;  { utf16 type from ntapi }
>   attr: OBJECT_ATTRIBUTES;
>   io: IO_STATUS_BLOCK;
>   ntmode: Integer;
>   Handle: longword;
> begin
>   attr.Length := sizeof(attr);
>   attr.RootDirectory := 0;
>   attr.Attributes := 0;
>   attr.ObjectName := @str;
>   attr.SecurityDescriptor := nil;
>   attr.SecurityQualityOfService := nil;
>
>   NtOpenFile(@Handle, ntmode, @attr, @io, FileShareMode,
> FILE_NON_DIRECTORY_FILE or FILE_SYNCHRONOUS_IO_NONALERT)
> end;
>
>
>
> So in core, winnt is working with UTF16. All ANSI Winapi functions map
> to these winnt calls.
>
> -Ivo Steinmann
>   

that's the object_attributes type

  OBJECT_ATTRIBUTES = record
    Length: ULONG;
    RootDirectory: HANDLE;
    ObjectName: PUNICODE_STRING;
    Attributes: ULONG;
    SecurityDescriptor: PVOID;       // Points to type SECURITY_DESCRIPTOR
    SecurityQualityOfService: PVOID; // Points to type
SECURITY_QUALITY_OF_SERVICE
  end;


if fpc would use ntapi instead of winapi (maybe it do, no idea) it would
be faster, because there's no overhead at all :)  at least with new
UnicodeString type. ntapi is also quite near to functions you know as
syscalls from unix.

-Ivo



More information about the fpc-devel mailing list