public void AllocValueTypeAndCopy(StackObject *ptr, StackObject *src) { var dst = ILIntepreter.ResolveReference(src); var type = intepreter.AppDomain.GetType(dst->Value); int size, managedCount; type.GetValueTypeSize(out size, out managedCount); if (allocator == null) { allocator = new StackObjectAllocator(AllocBlock); } StackObjectAllocation alloc; if (allocator.AllocExisting(ptr, size, managedCount, out alloc)) { if (dst != alloc.Address) { dst = alloc.Address; ptr->ObjectType = ObjectTypes.ValueTypeObjectReference; *(long *)&ptr->Value = (long)dst; int managedIdx = alloc.ManagedIndex; InitializeValueTypeObject(type, dst, true, ref managedIdx); intepreter.CopyStackValueType(src, ptr, managedStack); FreeValueTypeObject(src); } else { ptr->ObjectType = ObjectTypes.ValueTypeObjectReference; *(long *)&ptr->Value = (long)dst; } } else { int start = int.MaxValue; int end = int.MinValue; StackObject *endAddr; CountValueTypeManaged(src, ref start, ref end, &endAddr); if (endAddr == valueTypePtr) { valueTypePtr = dst; } allocator.RegisterAllocation(ptr, dst, size, start, managedCount); ptr->ObjectType = ObjectTypes.ValueTypeObjectReference; *(long *)&ptr->Value = (long)dst; } }