[Overview][Constants][Types][Procedures and functions][Index] Reference for unit 'heaptrc' (#rtl)

SetHeapExtraInfo

Store extra information in blocks.

Declaration

Source position: heaptrc.pp line 50

procedure SetHeapExtraInfo(

  size: ptruint;

  fillproc: tFillExtraInfoProc;

  displayproc: tdisplayextrainfoProc

);

Description

You can use SetHeapExtraInfo to store extra info in the blocks that the heaptrc unit reserves when tracing getmem calls. Size indicates the size (in bytes) that the trace mechanism should reserve for your extra information. For each call to getmem, FillProc will be called, and passed a pointer to the memory reserved.

When dumping the memory summary, the extra info is shown by calling displayproc and passing it the memory location which was filled by fillproc. It should write the information in readable form to the text file provided in the call to displayproc

Errors

You can only call SetHeapExtraInfo if no memory has been allocated yet. If memory was already allocated prior to the call to SetHeapExtraInfo, then an error will be displayed on standard error output, and a DumpHeap is executed.

See also

DumpHeap

  

Dump memory usage report to stderr.

SetHeapTraceOutput

  

Specify filename for heap trace output.

Example

Program heapex;

{ Program used to demonstrate the usage of heaptrc unit }

Uses heaptrc;

Var P1 : ^Longint;
    P2 : Pointer;
    I : longint;
    Marker : Longint;

Procedure SetMarker (P : pointer);

Type PLongint = ^Longint;

begin
  PLongint(P)^:=Marker;
end;

Procedure  Part1;

begin
  // Blocks allocated here are marked with $FFAAFFAA = -5570646
  Marker := $FFAAFFAA;
  New(P1);
  New(P1);
  Dispose(P1);
  For I:=1 to 10 do
    begin
    GetMem (P2,128);
    If (I mod 2) = 0 Then FreeMem(P2,128);
    end;
  GetMem(P2,128);
end;

Procedure  Part2;

begin
  // Blocks allocated here are marked with $FAFAFAFA = -84215046
  Marker := $FAFAFAFA;
  New(P1);
  New(P1);
  Dispose(P1);
  For I:=1 to 10 do
    begin
    GetMem (P2,128);
    If (I mod 2) = 0 Then FreeMem(P2,128);
    end;
  GetMem(P2,128);
end;

begin
 SetExtraInfo(SizeOf(Marker),@SetMarker);
 Writeln ('Part 1');
 part1;
 Writeln('Part 2');
 part2;
end.

Documentation generated on: Jun 23 2021