本文整理汇总了C++中MethodTable::InitializeFreeObject方法的典型用法代码示例。如果您正苦于以下问题:C++ MethodTable::InitializeFreeObject方法的具体用法?C++ MethodTable::InitializeFreeObject怎么用?C++ MethodTable::InitializeFreeObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MethodTable
的用法示例。
在下文中一共展示了MethodTable::InitializeFreeObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int __cdecl main(int argc, char* argv[])
{
//
// Initialize system info
//
if (!GCToOSInterface::Initialize())
{
return -1;
}
//
// Initialize free object methodtable. The GC uses a special array-like methodtable as placeholder
// for collected free space.
//
static MethodTable freeObjectMT;
freeObjectMT.InitializeFreeObject();
g_pFreeObjectMethodTable = &freeObjectMT;
//
// Initialize GC heap
//
GcDacVars dacVars;
IGCHeap *pGCHeap;
IGCHandleManager *pGCHandleManager;
if (!InitializeGarbageCollector(nullptr, &pGCHeap, &pGCHandleManager, &dacVars))
{
return -1;
}
if (FAILED(pGCHeap->Initialize()))
return -1;
//
// Initialize handle manager
//
if (!pGCHandleManager->Initialize())
return -1;
//
// Initialize current thread
//
ThreadStore::AttachCurrentThread();
//
// Create a Methodtable with GCDesc
//
class My : Object {
public:
Object * m_pOther1;
int dummy_inbetween;
Object * m_pOther2;
};
static struct My_MethodTable
{
// GCDesc
CGCDescSeries m_series[2];
size_t m_numSeries;
// The actual methodtable
MethodTable m_MT;
}
My_MethodTable;
// 'My' contains the MethodTable*
uint32_t baseSize = sizeof(My);
// GC expects the size of ObjHeader (extra void*) to be included in the size.
baseSize = baseSize + sizeof(ObjHeader);
// Add padding as necessary. GC requires the object size to be at least MIN_OBJECT_SIZE.
My_MethodTable.m_MT.m_baseSize = max(baseSize, MIN_OBJECT_SIZE);
My_MethodTable.m_MT.m_componentSize = 0; // Array component size
My_MethodTable.m_MT.m_flags = MTFlag_ContainsPointers;
My_MethodTable.m_numSeries = 2;
// The GC walks the series backwards. It expects the offsets to be sorted in descending order.
My_MethodTable.m_series[0].SetSeriesOffset(offsetof(My, m_pOther2));
My_MethodTable.m_series[0].SetSeriesCount(1);
My_MethodTable.m_series[0].seriessize -= My_MethodTable.m_MT.m_baseSize;
My_MethodTable.m_series[1].SetSeriesOffset(offsetof(My, m_pOther1));
My_MethodTable.m_series[1].SetSeriesCount(1);
My_MethodTable.m_series[1].seriessize -= My_MethodTable.m_MT.m_baseSize;
MethodTable * pMyMethodTable = &My_MethodTable.m_MT;
// Allocate instance of MyObject
Object * pObj = AllocateObject(pMyMethodTable);
if (pObj == NULL)
return -1;
// Create strong handle and store the object into it
OBJECTHANDLE oh = HndCreateHandle(g_HandleTableMap.pBuckets[0]->pTable[GetCurrentThreadHomeHeapNumber()], HNDTYPE_DEFAULT, pObj);
if (oh == NULL)
return -1;
for (int i = 0; i < 1000000; i++)
{
//.........这里部分代码省略.........
示例2: main
int __cdecl main(int argc, char* argv[])
{
//
// Initialize system info
//
if (!GCToOSInterface::Initialize())
{
return -1;
}
//
// Initialize free object methodtable. The GC uses a special array-like methodtable as placeholder
// for collected free space.
//
static MethodTable freeObjectMT;
freeObjectMT.InitializeFreeObject();
g_pFreeObjectMethodTable = &freeObjectMT;
//
// Initialize handle table
//
if (!Ref_Initialize())
return -1;
//
// Initialize GC heap
//
GCHeap *pGCHeap = GCHeap::CreateGCHeap();
if (!pGCHeap)
return -1;
if (FAILED(pGCHeap->Initialize()))
return -1;
//
// Initialize current thread
//
ThreadStore::AttachCurrentThread();
//
// Create a Methodtable with GCDesc
//
class My : Object {
public:
Object * m_pOther1;
int dummy_inbetween;
Object * m_pOther2;
};
static struct My_MethodTable
{
// GCDesc
CGCDescSeries m_series[2];
size_t m_numSeries;
// The actual methodtable
MethodTable m_MT;
}
My_MethodTable;
// 'My' contains the MethodTable*
uint32_t baseSize = sizeof(My);
// GC expects the size of ObjHeader (extra void*) to be included in the size.
baseSize = baseSize + sizeof(ObjHeader);
// Add padding as necessary. GC requires the object size to be at least MIN_OBJECT_SIZE.
My_MethodTable.m_MT.m_baseSize = max(baseSize, MIN_OBJECT_SIZE);
My_MethodTable.m_MT.m_componentSize = 0; // Array component size
My_MethodTable.m_MT.m_flags = MTFlag_ContainsPointers;
My_MethodTable.m_numSeries = 2;
// The GC walks the series backwards. It expects the offsets to be sorted in descending order.
My_MethodTable.m_series[0].SetSeriesOffset(offsetof(My, m_pOther2));
My_MethodTable.m_series[0].SetSeriesCount(1);
My_MethodTable.m_series[0].seriessize -= My_MethodTable.m_MT.m_baseSize;
My_MethodTable.m_series[1].SetSeriesOffset(offsetof(My, m_pOther1));
My_MethodTable.m_series[1].SetSeriesCount(1);
My_MethodTable.m_series[1].seriessize -= My_MethodTable.m_MT.m_baseSize;
MethodTable * pMyMethodTable = &My_MethodTable.m_MT;
// Allocate instance of MyObject
Object * pObj = AllocateObject(pMyMethodTable);
if (pObj == NULL)
return -1;
// Create strong handle and store the object into it
OBJECTHANDLE oh = CreateGlobalHandle(pObj);
if (oh == NULL)
return -1;
for (int i = 0; i < 1000000; i++)
{
Object * pBefore = ((My *)ObjectFromHandle(oh))->m_pOther1;
// Allocate more instances of the same object
Object * p = AllocateObject(pMyMethodTable);
//.........这里部分代码省略.........