program AllocateMemory;
var
MemoryBlock: Pointer; // Pointer to hold the allocated memory
Size: LongInt;
begin
Size := 1024 * 1024; // 1 megabyte (1,048,576 bytes)
GetMem(MemoryBlock, Size); // Allocate memory
if MemoryBlock <> nil then
begin
WriteLn('Memory successfully allocated.');
// Use the memory here...
FreeMem(MemoryBlock, Size); // Free the allocated memory
WriteLn('Memory successfully freed.');
end
else
WriteLn('Memory allocation failed.');
end.
(*
run:
Memory successfully allocated.
Memory successfully freed.
*)