LoadFromMappedFile

Document management, Performance, File input

Description

Loads and selects a local PDF through a bounded read-only mapped view, allowing large deferred object and stream reads to reuse operating-system file pages without retaining the complete source in memory

Syntax

Delphi

Function TPDFlib.LoadFromMappedFile(Const FileName, Password: WideString;
  WindowSize: Int64= 0; Options: Integer= 0): Integer;

Parameters

FileNameThe path of the local PDF
PasswordThe password used to open the PDF, or an empty string for an unencrypted document
WindowSizeThe requested mapped-view size in bytes; zero selects 64 MiB, values below the operating-system allocation granularity are raised to that granularity and values above 1 GiB are capped
OptionsZero permits a read-only file-stream fallback, while PDF_MAPPED_FILE_REQUIRE_MAPPING fails unless a mapped view is active

Return values

0The arguments were invalid, the file could not be opened, required mapping was unavailable or the PDF could not be loaded; inspect LastErrorCode
1The document was loaded and selected

Remarks

Windows builds retain one read-only view and remap it on demand at allocation-granularity boundaries; other platforms and mapping failures use the same absolute-read contract over a normal read-only file stream unless mapping is required

The default 64 MiB view bounds address-space use independently of source size and is suitable for sparse access to large local files; a smaller view can reduce resident address space at the cost of more remaps

Absolute object-slice reads copy directly from the current view into parser-owned storage without changing the positional stream cursor; this is not a persistent zero-copy pointer API because remapping invalidates view addresses

The source remains open until the loaded document is removed, and saving or deferred extraction can continue reading it

OnPassword is assigned, every rejected password retry receives a fresh mapped stream and parser state. Use

GetMappedFileInfo to confirm whether mapping is active and inspect current view and read statistics