SciSharp / NumSharp

High Performance Computation for N-D Tensors in .NET, similar API to NumPy.
https://github.com/SciSharp
Apache License 2.0
1.34k stars 188 forks source link

AccessViolationException when selecting indexes using ndarray[ndarray] and setting a scalar value #434

Open lijianxin520 opened 3 years ago

lijianxin520 commented 3 years ago

Attempted to read or write protected memory. This is often an indication that other memory is corrupt. 2020-12-30_230218

rikkitook commented 3 years ago

To my experience, problems like these can be avoided if you do not access an instance of ndarray from different threads or tasks. If it is still necessary, try copying ndarray to float[], pass it to your method and then copy to new ndarray. Cheers!

lijianxin520 commented 3 years ago

I'm single-threaded, so I shouldn't have any problems with multithreading

Nucs commented 3 years ago

To my understanding - AccessViolationException usually occurs if you somehow lost reference to your NDArray. NDArray only frees allocated memory when IDisposable is triggered by the garbage collector when there are no longer any references to it. In addition, zero-copied NDArrays from any operation still hold a reference to base memory which should prevent deallocation.

Please provide here a reproducing unit test/piece of code and I'll gladly investigate.

lijianxin520 commented 3 years ago

这个是我测试的时候异常的内容, image 当我对一个数组执行批处理操作时,我看到的结果是这个问题.