0

我的内存是 4GB(2.99GB 可用,但我不知道为什么)。在C# Visual Studio 2010项目中使用Bluebit Library处理Matrix时,在Windows Form Application中执行代码并连接数据库后,出现NotEnoughMemoryException(没有足够的内存继续执行),使用的物理内存为2.14GB,但是在控制台应用程序中单独使用代码时不会出现任何异常。

StreamWriter aWr = new StreamWriter("aMatrix.mtx");
Matrix aMatrix = new Matrix(termsList.Count, Docs.Count);
/////load aMatrix from DataBase and aMatrix[8200, 40]

SVD svd = new SVD(aMatrix);
StreamWriter sWr = new StreamWriter("sMatrix.mtx");
Matrix S = svd.S.SubMatrix(0, k - 1, 0, k - 1);
for (int row = 0; row < S.Rows; row++)
{
        for (int col = 0; col < S.Cols; col++)
            sWr.Write(S[row, col] + "\t");
        sWr.Write("\n");
}
sWr.Close();

StreamWriter uWr = new StreamWriter("uMatrix.mtx");
Matrix U = svd.U;
nt endRaws = U.Rows - 1;
U = U.SubMatrix(0, endRaws, 0, k - 1);
for (int row = 0; row < U.Rows; row++)                                                      
{
    for (int col = 0; col < U.Cols; col++)
        uWr.Write(U[row, col] + "\t");
    uWr.Write("\n");
}
uWr.Close();

StreamWriter vWr = new StreamWriter("vMatrix.mtx");
Matrix V = svd.V;
endRaws = V.Rows - 1;
V = V.SubMatrix(0, endRaws, 0, k - 1);
for (int row = 0; row < V.Rows; row++)
{
    for (int col = 0; col < V.Cols; col++)
        vWr.Write(V[row, col] + "\t");
    vWr.Write("\n");
}
vWr.Close();

StreamWriter vtWr = new StreamWriter("vtMatrix.mtx");
Matrix VT = new Matrix(V.Cols, V.Rows);
for (int row = 0; row < V.Rows; row++)
    for (int col = 0; col < V.Cols; col++)
        VT[col, row] = V[row, col];

for (int row = 0; row < VT.Rows; row++)
{
    for (int col = 0; col < VT.Cols; col++)
        vtWr.Write(VT[row, col] + "\t");
    vtWr.Write("\n");
}
vtWr.Close();

我如何管理我的记忆?

4

1 回答 1

0

您需要在 x64 模式下构建您的应用程序以使用超过 2Gb 每个进程,请参阅为什么我的 C# 应用程序中出现内存不足异常?

于 2012-05-01T19:52:02.150 回答