unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TfMain = class(TForm)
    btnAllocMem: TButton;
    btnTest: TButton;
    procedure btnAllocMemClick(Sender: TObject);
    procedure btnTestClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  PArr = ^TArr;
  TArr = array[1..250] of byte;

var
  fMain : TfMain;
  Arr   : PArr;
  pMem  : pointer;

const
  Address = 100 * 1024 * 1024;
  PageCnt = 500;
  PageSize = 4096 * 2;
  Size = PageSize * PageCnt;

implementation

{$R *.dfm}

procedure TfMain.btnAllocMemClick(Sender: TObject);
begin
  pMem := VirtualAlloc(nil, Size, MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE);
  if pMem = nil then ShowMessage('Помилка виділення пам''яті!');
end;

procedure TfMain.btnTestClick(Sender: TObject);
var I : byte;
begin
  Arr := VirtualAlloc(nil, SizeOf(TArr), MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE);
  for I := 1 to 250 do Arr^[I] := I;

  ShowMessage(IntToStr(Arr^[107]));

  VirtualFree(Arr, 0, MEM_RELEASE);
end;

end.
