This change makes scrolling through multi-page documents cheaper by tracking how far the current window moved and only freeing, shifting, and rendering the page buffers that actually changed. Previously, loadpage() rebuilt the visible page set from scratch; now it preserves still-visible pages and allocates the page buffer array once during startup, which should reduce redraw work and memory churn. It also adjusts cleanup to free the full allocated buffer range safely. The practical effect is smoother scrolling and less wasted rendering when moving page by page.