让我说我有一些大的对象。我将此对象传递给要使用的函数。调用doSomthingRef实际上会阻止对象再次被复制,这可能会减少OOM异常的可能性吗?
示例:
HugeObject ho = new HugeObject();
private void doSomthing1(HugeObject h)
{
var value = h.value;
if (h.conditional) {finalStep(value);}
}
private void doSomthingRef(ref HugeObject refh)
{
if (refh.conditional) {finalStep( ref refh.value);}
}
int finalStep (TypeOfValue value)
{
//magic
}
int finalStep (ref TypeOfValue value)
{
//magic
}