Delphi Language Guide Delphi for Microsoft Win32 Delphi for the Microsoft. Net framework



Yüklə 0,84 Mb.
Pdf görüntüsü
səhifə240/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   236   237   238   239   240   241   242   243   ...   294
DelphiLanguageGuide

Memory Management
This section describes memory management issues related to programming in Delphi on Win32, and on .NET.
204


Memory Management on the Win32 Platform
The following material describes how memory management on Win32 is handled, and briefly describes memory
issues of variables.
The Memory Manager (Win32 Only)
The memory manager manages all dynamic memory allocations and deallocations in an application. The 
New
,
Dispose

GetMem

ReallocMem
, and 
FreeMem
 standard procedures use the memory manager, and all objects
and long strings are allocated through the memory manager.
The memory manager is optimized for applications that allocate large numbers of small- to medium-sized blocks,
as is typical for object-oriented applications and applications that process string data. Other memory managers, such
as the implementations of 
GlobalAlloc

LocalAlloc
, and private heap support in Windows, typically do not
perform well in such situations, and would slow down an application if they were used directly.
To ensure the best performance, the memory manager interfaces directly with the Win32 virtual memory API (the
VirtualAlloc
 and 
VirtualFree
 functions). The memory manager reserves memory from the operating system
in 1Mb sections of address space, and commits memory as required in 16K increments. It decommits and releases
unused memory in 16K and 1Mb sections. For smaller blocks, committed memory is further suballocated.
Memory manager blocks are always rounded upward to a 4-byte boundary, and always include a 4-byte header in
which the size of the block and other status bits are stored. This means that memory manager blocks are always
double-word-aligned, which guarantees optimal CPU performance when addressing the block.
The memory manager maintains two status variables
AllocMemCount
 and 
AllocMemSize
, which contain the
number of currently allocated memory blocks and the combined size of all currently allocated memory blocks.
Applications can use these variables to display status information for debugging.
The 
System
 unit provides two procedures, 
GetMemoryManager
 and 
SetMemoryManager
, that allow applications
to intercept low-level memory manager calls. The 
System
 unit also provides a function called 
GetHeapStatus
 that
returns a record containing detailed memory-manager status information.

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   236   237   238   239   240   241   242   243   ...   294




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin