开发者

Which method is better?

I am using an import to open a connected physical hard-drive:

var sfh = Imports.CreateFile(Path, Imports.FileAccess.GenericAll, Imports.FileShare.None, IntPtr.Zero, Imports.CreationDisposition.OpenExisting, 0, IntPtr.Zero);
if (sfh.IsInvalid)
{
    Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
    return;
}
Geometry = Imports.GetGeometry(sfh);
var fs = new FileStream(sfh, FileAccess.ReadWrite, (int)Geometry.BytesPerSector, false);

That works fine, but instead of using FileStream, I was wondering if this would be a more efficient way to read bytes from the drive: http://msdn.microsoft.com/en-us/library/aa36开发者_C百科5467%28v=VS.85%29.aspx


Is speed and/or efficiency that important for you ?? because the difference is probably minor in this case...

It seems like the link you gave uses a WinAPI method. I would avoid using these were you don't necessarily have to since the .net GarbageCollector doesn't play well with Native resources, and you might suffer from memory leaks if you don't handle these correctly...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜