This sample demonstrates how to use information from the Delphi memory manager to graphically display the memory block allocation.
You can find the Usage Tracker sample project at:
- Start > Programs > Embarcadero RAD Studio > Samples > Delphi > RTL > Usage Tracker
- Subversion Repository for Delphi: http://sourceforge.net/p/radstudiodemos/code/HEAD/tree/branches/RadStudio_XE4/Delphi/RTL/Usage%20Tracker/
This application consists of two forms. The first form allows the user to choose the minimum block alignment and then display the usage tracker itself, by clicking the Show Usage Tracker button. The usage tracker form contains a TDrawGrid component, used to graphically display the allocated blocks of memory in different colors, depending on their type. Below the TDrawGrid, two TEdit components display the address and state of the selected block. To the right of the form, a TStringGrid displays statistics about the allocated blocks, including their size, reserved memory, and efficiency.
How to Use the Sample
- Navigate to Start | Programs | Embarcadero RAD Studio | Samples and open UsageTrackerDemo.dproj.
- Press F9 or choose Run > Run.
The project has two source files:
The class for the form that is displayed first when the application is run.
The class for the usage tracker.
- TfDemo is the class for the form that allows the user to choose the minimum block alignment and then to display the usage tracker form.
- TfMemoryManagerUsageTracker is the class for the form that graphically displays memory allocation information. It retrieves data from the memory manager and displays it in a TDrawGrid component and a TStringGrid component.
- GetMemoryMap is used to retrieve the map of the address space and GetMemoryManagerState is used to get memory usage statistics. GetMemoryManagerState returns a TMemoryManagerState record that contains information about blocks of all sizes--small, medium, and large. GetMemoryMap returns a TMemoryMap, which is an array that contains the status of each block of memory.
- TStringGrid.Cells is used to access individual cells in the grid.
- A TTimer component is used to periodically refresh the two grids.