ICorProfilerInfo2::GetGenerationBounds 方法ICorProfilerInfo2::GetGenerationBounds Method

获取属于堆段的内存区域,堆段构成各代垃圾回收。Gets the memory regions, which are segments of the heap, that make up the various garbage collection generations.

语法Syntax

HRESULT GetGenerationBounds(  
    [in]  ULONG cObjectRanges,  
    [out] ULONG *pcObjectRanges,  
    [out, size_is(cObjectRanges), length_is(*pcObjectRanges)] COR_PRF_GC_GENERATION_RANGE ranges[]);  

参数Parameters

cObjectRanges
[in] 由调用方为 ranges 数组分配的元素数目。[in] The number of elements allocated by the caller for the ranges array.

pcObjectRanges
[out] 指向指定范围总数的整数的指针,部分或所有范围都将在 ranges 数组中返回。[out] A pointer to an integer that specifies the total number of ranges, some or all of which will be returned in the ranges array.

ranges
COR_PRF_GC_GENERATION_RANGE结构的数组,其中每个结构都描述了要进行垃圾回收的代内内存的范围(即块)。[out] An array of COR_PRF_GC_GENERATION_RANGE structures, each of which describes a range (that is, block) of memory within the generation that is undergoing garbage collection.

注解Remarks

可以从任何探查器回调调用 GetGenerationBounds 方法,前提是当前未进行垃圾回收。The GetGenerationBounds method can be called from any profiler callback, provided that garbage collection is not in progress.

大多数代切换都发生在垃圾回收期间。Most shifting of generations takes place during garbage collections. 在回收之间,代可能会增长,但通常不会反复切换。Generations might grow between collections but generally do not move around. 因此,调用 GetGenerationBounds 最具特色的地方在于 ICorProfilerCallback2::GarbageCollectionStartedICorProfilerCallback2::GarbageCollectionFinished 中。Therefore, the most interesting places to call GetGenerationBounds are in ICorProfilerCallback2::GarbageCollectionStarted and ICorProfilerCallback2::GarbageCollectionFinished.

在程序启动期间,某些对象是由公共语言运行时 (CLR) 自身分配的,通常发生在第 3 代和第 0 代中。During program startup, some objects are allocated by the common language runtime (CLR) itself, generally in generations 3 and 0. 因此,当托管代码开始执行时,这些代将已经包含对象。Thus, by the time managed code starts executing, these generations will already contain objects. 第 1 代和第 2 代通常将为空,但由垃圾回收器生成的虚拟对象除外。Generations 1 and 2 will normally be empty, except for dummy objects that are generated by the garbage collector. (在 CLR 的32位实现中,虚拟对象的大小为12个字节; 64 位实现中的大小较大。)你还可能看到在本机映像生成器(Ngen.exe)生成的模块内的第2代范围。(The size of dummy objects is 12 bytes in 32-bit implementations of the CLR; the size is larger in 64-bit implementations.) You might also see generation 2 ranges that are inside modules produced by the Native Image Generator (NGen.exe). 在这种情况下,第2代中的对象是冻结对象,这些对象在 ngen.exe 运行时分配,而不是由垃圾回收器分配。In this case, the objects in generation 2 are frozen objects, which are allocated when NGen.exe runs rather than by the garbage collector.

此函数使用调用方分配的缓冲区。This function uses caller-allocated buffers.

要求Requirements

平台: 请参阅系统要求Platforms: See System Requirements.

头文件: CorProf.idl、CorProf.hHeader: CorProf.idl, CorProf.h

库: CorGuids.libLibrary: CorGuids.lib

.NET Framework 版本:自 2.0 之后可用Available since 2.0.NET Framework Versions: 自 2.0 之后可用Available since 2.0

另请参阅See also