Memory Management

来源:互联网 发布:淘宝上面有大麻饼干 编辑:程序博客网 时间:2024/06/09 13:46
The Memory Manager (Win32 Only)
内存管理器(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.

内存管理器管理应用程序中所有动态内存的分配和释放。New,Dispose,GetMem,ReallocMem和FreeMem这些过程使用了内存管理器,所有的对象和长字符串通过内存管理器来分配。

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. The Memory Manager is optimized for efficient operation (high speed and low memory overhead) in single and multi-threaded applications. 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.

对于应用程序,内存管理器被优化,把内存分配成很多小-到中-大小的块。其中典型的有面向对象应用程序和处理字符串数据应用程序。对单/多线程应用程序的高效的操作(高速低内存开销)进行了内存管理器的优化。其他内存管理器,比如Windows中的GlobalAlloc, LocalAlloc和私有堆支持,在这方面执行的都不是很好,并且如果直接调用的话会拖慢应用程序。

To ensure the best performance, the Memory Manager interfaces directly with the Win32 virtual memory API (the >VirtualAlloc and VirtualFree functions). The Memory Manager supports a user mode address space up to 4GB. 

Memory Manager blocks are always rounded upward to a size that is a multiple of 4 bytes, and always include a 4-byte header in which the size of the block and other status bits are stored. The start address of memory blocks are always aligned on at least 8-byte boundaries, or optionally on 16-byte boundaries, which improves performance when addressing them.

要确保最佳执行,内存管理者接口和windows32中的虚拟内存api(VirtualAlloc和VirtualFree函数)。内存管理器支持用户模式的地址可以达到4G。内存管理器块总是四舍五入为4字节的倍数,并且总是包含4字节的头部,其中包含了块的大小和其他状态标志位。内存块的起始地址总是至少与8字节边界对齐,或者16字节边界,这样能够在执行的时候改善寻址。

The Memory Manager employs an algorithm that anticipates future block reallocations, reducing the performance impact usually associated with such operations. The reallocation algorithm also helps reduce address space fragmentation.

内存管理器使用一种算法来预计要重分配的块,减少通常与这些操作有关的影响。重分配算法也有助于减少地址空间的碎片。

The memory manager provides a sharing mechanism that does not require the use of an external DLL. 

The Memory Manager includes reporting functions to help applications monitor their own memory usage and potential memory leaks. 

内存管理器提供一种共享机制不需要使用额外的dll。内存管理器包含汇报功能帮助应用程序监视他们自己的内存使用和潜在的内存泄漏。

The Memory Manager provides two procedures, GetMemoryManagerState and GetMemoryMap, that allow applications to retrieve memory-manager status information and a detailed map of memory usage.

内存管理器提供两个函数,GetMemoryManagerState 和 GetMemoryMap,允许应用程序获取内存管理器状态信息和详细的内存使用图。

Variables
变量

Global variables are allocated on the application data segment and persist for the duration of the program. Local variables (declared within procedures and functions) reside in an application's stack. Each time a procedure or function is called, it allocates a set of local variables; on exit, the local variables are disposed of. Compiler optimization may eliminate variables earlier.

全局变量被分配在应用程序的数据段,存活于真个程序范围。局部变量(在过程和函数中声明)存在于应用程序的栈中。每当一个过程或函数被调用,分配一组局部变量,退出时,局部变量被释放。编译器优化能排除变量早期的。

On Win32, an application's stack is defined by two values: the minimum stack size and the maximum stack size. The values are controlled through the $MINSTACKSIZE and $MAXSTACKSIZE compiler directives, and default to 16,384 (16K) and 1,048,576 (1Mb) respectively. An application is guaranteed to have the minimum stack size available, and an application's stack is never allowed to grow larger than the maximum stack size. If there is not enough memory available to satisfy an application's minimum stack requirement, Windows will report an error upon attempting to start the application. 

If a Win32 application requires more stack space than specified by the minimum stack size, additional memory is automatically allocated in 4K increments. If allocation of additional stack space fails, either because more memory is not available or because the total size of the stack would exceed the maximum stack size, an EStackOverflow exception is raised. (Stack overflow checking is completely automatic. The $S compiler directive, which originally controlled overflow checking, is maintained for backward compatibility.) 

Dynamic variables created with the GetMem or New procedure are heap-allocated and persist until they are deallocated with FreeMem or Dispose. 

Long strings, wide strings, dynamic arrays, variants, and interfaces are heap-allocated, but their memory is managed automatically.


原创粉丝点击