-4

バイナリファイルを読んでいます。1 つのファイルを読み取ると、コードは正常に動作します。しかし、フォルダー内のファイルを読み取ると、エラーが発生し、以下に貼り付けられます。ファイルの読み取りに使用しているコードをいくつか追加します。私はバイト配列でファイルを読んでいます:

byte[] b = File.ReadAllBytes(args);

データを配列に格納する (指標コード):

len=400000000;
public ArrayList rawData1 = new ArrayList();
UInt32[] fff = Enumerable.Repeat((UInt32)4095, len/4).ToArray();    


public ReadRawFiles{
            while (true){
            rawData1.Add((double)(BitConverter.ToUInt32(b, curPos) & fff[i]));
            i++;
            }
}
b=null; //clear array

ファイルを 1 つだけ読み込むと、速度は遅くなりますが (サイズは約 40 MB)、動作します。しかし、フォルダーのパスを追加して再度読み取ると、エラーが発生します。

List<ReadRawFiles> list = new List<ReadRawFiles>();
ReadRawFiles rawFiles;
foreach (var f in sFiles)
                    {
                      rawFiles = new ReadRawFiles(f.File,true,true);
                      list.Add(rawFiles);

                       //rawFiles=null; //clear??
                    }

ガベージコレクターの仕組みがよくわかりません。何か見逃した場合はお知らせください。

よろしくお願いします。

編集: コード: http://www.codesend.com/view/4aadd067dfd26ea88396afbd3cd3fc22/ http://www.codesend.com/view/f8f798224e54c28a00865ca9aff514e5/

System.OutOfMemoryException was unhandled
  Message=Exception of type 'System.OutOfMemoryException' was thrown.
  Source=System.Core
  StackTrace:
       at System.Linq.Buffer`1.ToArray()
       at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
       at program.ReadRawFiles..ctor(String args, Nullable`1 flagraw, Nullable`1 dualChannel) in E:\projects\development\vs_test\WpfApplication1\WpfApplication1\param.cs:line 83
       at SePSI.MainWindow.Add_folder(Object sender, RoutedEventArgs e) in E:\projects\development\vs_test\WpfApplication1\WpfApplication1\MainWindow.xaml.cs:line 196
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
       at System.Windows.Controls.MenuItem.InvokeClickAfterRender(Object arg)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Windows.Threading.DispatcherOperation.Invoke()
       at System.Windows.Threading.Dispatcher.ProcessQueue()
       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run(Window window)
       at System.Windows.Application.Run()
       at SePSI.App.Main() in E:\projects\development\vs_test\WpfApplication1\WpfApplication1\obj\x86\Debug\App.g.cs:line 0
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
4

2 に答える 2

1

私はそれがこれによるものだと思います:

while (true)
{
    rawData1.Add((double)(BitConverter.ToUInt32(b, curPos) & fff[i]));
    i++;
}

終了条件はありません。それは永遠に続き、データをインクリメントしてArrayListiに追加することでリソースを消費し続けます。rawData

于 2013-05-07T12:48:04.727 に答える