zoukankan      html  css  js  c++  java
  • 内存管理六

    本例效果图:


    unit Unit1;
    interface
    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls;
    type
    TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Memo1: TMemo;
    Memo2: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    end;
    var
    Form1: TForm1;
    implementation
    {$R *.dfm}
    //测试堆的内存占用情况
    procedure TForm1.Button1Click(Sender: TObject);
    var
    MyHeap: THandle;
    mem: TMemoryStatus;
    m1,m2,m3: DWORD;
    begin
    {获取当前内存可用状态}
    GlobalMemoryStatus(mem);
    m1 := mem.dwAvailPhys;     {可用物理内存}
    m2 := mem.dwAvailPageFile; {可用虚拟内存}
    m3 := mem.dwAvailVirtual;  {可用虚拟地址}
    {建立私有堆}
    MyHeap := HeapCreate(HEAP_NO_SERIALIZE, 1024*1204, 0); {建立 1 M 大小的堆}
    {再获取当前内存可用状态}
    GlobalMemoryStatus(mem);
    m1 := m1 - mem.dwAvailPhys;
    m2 := m2 - mem.dwAvailPageFile;
    m3 := m3 - mem.dwAvailVirtual;
    {显示堆占用内存的情况}
    Memo1.Clear;
    Memo1.Lines.Add(Format('占用物理内存: %d K', [m1 div 1024]));
    Memo1.Lines.Add(Format('占用虚拟内存: %d K', [m2 div 1024]));
    Memo1.Lines.Add(Format('占用虚拟地址: %d K', [m3 div 1024]));
    {释放堆}
    HeapDestroy(MyHeap);
    end;
    //同上个过程, 外加测试建立堆时页对齐的情况
    procedure TForm1.Button2Click(Sender: TObject);
    var
    MyHeap: THandle;
    mem: TMemoryStatus;
    m1,m2,m3: DWORD;
    begin
    GlobalMemoryStatus(mem);
    m1 := mem.dwAvailPhys;
    m2 := mem.dwAvailPageFile;
    m3 := mem.dwAvailVirtual;
    {建立 1M + 1字节 大小的堆, 但实际大小会按页对齐, 结果应该是: 1M + 4K}
    MyHeap := HeapCreate(HEAP_NO_SERIALIZE, 1024*1204 + 1, 0);
    GlobalMemoryStatus(mem);
    m1 := m1 - mem.dwAvailPhys;
    m2 := m2 - mem.dwAvailPageFile;
    m3 := m3 - mem.dwAvailVirtual;
    Memo2.Clear;
    Memo2.Lines.Add(Format('占用物理内存: %d K', [m1 div 1024]));
    Memo2.Lines.Add(Format('占用虚拟内存: %d K', [m2 div 1024]));
    Memo2.Lines.Add(Format('占用虚拟地址: %d K', [m3 div 1024]));
    HeapDestroy(MyHeap);
    end;
    end.
    
  • 相关阅读:
    Ceph 之RGW Cache
    Ceph 之RGW Pub-Sub Module
    Ceph 之RGW Data Layout
    RocksDB 之Write Ahead Log(WAL)
    Ceph 之 Background on http frontends
    Ceph 之Multisite 下的bucket reshard
    Ceph之PG数调整
    Ceph之对象存储网关RADOS Gateway(RGW)
    window mysql重启、忘记密码等操作
    selenium处理HTML5视频播放未能自动播放解决办法
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/2940691.html
Copyright © 2011-2022 走看看