什么是Array.Clear实际上在幕后做什么? [英] What does Array.Clear actually do under the covers?
问题描述
我在寻找一个答案,在C#在幕后的Array.Clear(...)方法做什么。
I'm looking for a answer to what the Array.Clear(...) method does under the covers in C#.
我看过的IL,但并没有真正产生任何线索,因为它只是调用的System.Array ::清除(...)方法在mscorlib中,然后调用CLR的非托管部分我不能观察到。
I've looked at the IL, but that isn't really yielding any clues, since it simply calls the System.Array::Clear(...) method in mscorlib, which then calls an unmanaged portion of the CLR that I can't observe.
我为什么问这个,究其原因是,我偶尔会收到抛出我呼吁Array.Clear的SEHException,我似乎无法找出为什么它正在发生。
The reason why I am asking this, is that I am occasionally getting an SEHException thrown by my call to Array.Clear, and I can't seem to figure out why it is happening.
不幸的是,微软似乎有点守口如瓶它可能意味着,当异常被抛出...
Unfortunately, Microsoft seems to be a little tight-lipped about what it might mean when the exception is thrown...
从:<一href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.sehexception(v=VS.100).aspx">http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.sehexception(v=VS.100).aspx
任何SEH异常不会自动映射到一个特定的异常被映射到系统默认的SEHException类。欲了解更多信息,搜索非托管例外和结构化异常处理MSDN Library中。 的
在这个任何帮助将是AP preciated ......只是点我朝着正确的方向,即使!
Any help on this would be appreciated... just point me in the right direction, even!
谢谢!
推荐答案
您可以看到在SSCLI20源$ C $ C之类的code。它看起来像这样用全部去掉噪音:
You can see that kind of code in the SSCLI20 source code. Which looks like this with all the noise removed:
FCIMPL3(void, SystemNative::ArrayClear, ArrayBase* pArrayUNSAFE, INT32 iIndex, INT32 iLength)
{
BASEARRAYREF pArray = (BASEARRAYREF)pArrayUNSAFE;
// error checks
//..
char* array = (char*)pArray->GetDataPtr();
int size = pArray->GetMethodTable()->GetComponentSize();
ZeroMemory(array + (iIndex - lb) * size, iLength * size);
}
在换句话说,它简单地爆炸0字节到的元素。得到一个SEHException的唯一途径是通过处理器故障。 GC堆损坏。查看所有的PInvoke或COM互操作code。
In other words, it simply blasts 0 bytes into the elements. The only way to get an SEHException is through a processor fault. GC heap corruption. Review any pinvoke or COM interop code.
这篇关于什么是Array.Clear实际上在幕后做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!