Delphi7 (v)

Source: Internet
Author: User

This example obtains a list of heap handles for the current process by using the Getprocessheaps function before and after establishing a new heap.

UnitUnit1;InterfaceusesWindows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls;typeTForm1=class(tform) Memo1:tmemo;    Memo2:tmemo;    Button1:tbutton; procedureformcreate (Sender:tobject); procedureButton1Click (Sender:tobject); End;varForm1:tform1;Implementation{$R *.DFM}{extract the common parts of the following two processes as a separate process}proceduregetheaps (list:tstrings);varHeaparr:Array[0..9] ofThandle;{for a list of arrays, first assume that there are 10 heaps}N:integer; I:integer;begin  {gets the list of heaps in the process, parameter 1 of the function is the array size, parameter 2 is the first element of the array, returns the actual number of heaps}N:= Getprocessheaps (Length (Heaparr), heaparr[0]); List.add (Format ('There are%d heaps in the current process', [n])); List.add ('their handles are:');  forI: =0  toN-1  DoList.add (IntToStr (heaparr[i));End;proceduretform1.formcreate (sender:tobject);beginmemo1.clear; {calling a public procedure to display a list of heap handles in Memo1}getheaps (Memo1.lines); {add a handle to the default heap again}Memo1.Lines.Add ("'); MEMO1.LINES.ADD ('the handle to the default heap is:'); MEMO1.LINES.ADD (IntToStr (GetProcessHeap));End;procedureTform1.button1click (sender:tobject);varMyheap:thandle;begin  {Create a new heap}Myheap:= HeapCreate (0,1024x768*1024x768*2,0);{build a heap of 2M}memo2.clear; {calling a public procedure to display a list of heap handles in Memo2}getheaps (Memo2.lines); {add a handle to the new heap again}Memo2.Lines.Add ("'); MEMO2.LINES.ADD ('the handle to the new heap is:');  MEMO2.LINES.ADD (IntToStr (myheap)); {destroying the new heap}HeapDestroy (myheap);End;End.

Delphi7 (v)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.