乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      內存管理[4]

       獨孤求財 2012-03-30
      一個使用私有堆的例子:
      unit Unit1;
      
      interface
      
      uses
        Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
        Dialogs, StdCtrls;
      
      type
        TForm1 = class(TForm)
          Button1: TButton;
          procedure Button1Click(Sender: TObject);
        end;
      
      var
        Form1: TForm1;
      
      implementation
      
      {$R *.dfm}
      
      var
        MyHeap: THandle; {堆句柄}
        p: Pointer;
      
      procedure TForm1.Button1Click(Sender: TObject);
      var
        i,num: Integer;
        p2: Pointer;
        str: string;
      begin
        {建立堆}
        MyHeap := HeapCreate(HEAP_ZERO_MEMORY, 1024*1024*2, 0); {建立個 2M 的堆}
        if Myheap = 0 then Exit; {如果創(chuàng)建失敗則退出}
      
        {從堆中分配內存}
        p := HeapAlloc(MyHeap, 0, 7);
        if p = nil then Exit; {出錯退出}
      
        {獲取內存塊大小}
        num := HeapSize(MyHeap, 0, p);
      
        {給內存塊的每個字節(jié)賦值}
        p2 := p;
        for i := 0 to num - 1 do
        begin
          Byte(p2^) := i + 65;
          p2 := Ptr(Integer(p2) + 1);
        end;
      
        {取值}
        p2 := p;
        str := '';
        for i := 0 to num - 1 do
        begin
          str := str + Chr(Byte(p2^));
          p2 := Ptr(Integer(p2) + 1);
        end;
      
        {顯示內存塊的內容與大小}
        ShowMessageFmt('%s,%d',[str,num]); {ABCDEFG,7}
      
        /////////////////////////////////////////////////////
      
        {擴充內存, 只此一句不同, 下面都是重復上面的代碼}
        p := HeapReAlloc(MyHeap, 0, p, 26);
        if p = nil then Exit; {出錯退出}
      
        {獲取內存塊大小}
        num := HeapSize(MyHeap, 0, p);
      
        {給內存塊的每個字節(jié)賦值}
        p2 := p;
        for i := 0 to num - 1 do
        begin
          Byte(p2^) := i + 65;
          p2 := Ptr(Integer(p2) + 1);
        end;
      
        {取值}
        p2 := p;
        str := '';
        for i := 0 to num - 1 do
        begin
          str := str + Chr(Byte(p2^));
          p2 := Ptr(Integer(p2) + 1);
        end;
      
        {顯示內存塊的內容與大小}
        ShowMessageFmt('%s,%d',[str,num]); {ABCDEFGHIJKLMNOPQRSTUVWXYZ,26}
      
        /////////////////////////////////////////////////////
      
        {釋放內存}
        HeapFree(MyHeap, 0, p);
      
        {銷毀堆}
        HeapDestroy(MyHeap);
      end;
      
      end.
      

        本站是提供個人知識管理的網絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現有害或侵權內容,請點擊一鍵舉報。
        轉藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多