我在赋予参数(50,50)的时候重复调用几次会内存溢出。
当赋值(100,100)的时候直接嗝屁。
不懂如何释放资源,求解。
我电脑4G内存,xp。
做扫雷大家有什么其他好的思路也请不吝赐教。class Mine
{
public static int[,] matrixMines = null;//雷分布矩阵
public static int[,] matrixDigged = null;//当前位置是否点击过矩阵
public static int[,] matrixAround = null;//当前位置周围八个点的雷的总数 public Mine()
{
} public void FreshMines(byte x,byte y)
{
int[,] temp = new int[x+2,y+2];
matrixAround = (int[,])temp.Clone();
matrixDigged = (int[,]) temp.Clone(); Random r =new Random();
int[] random = new int[x * y * (r.Next(10,15)) / 100];
for (int i = 0; i < random.Length; i++)
{
random[i] = -1;
}
for (int i = 0; i < random.Length; )
{
int tmp = r.Next(0, x*y-1);
if (!random.Contains(tmp))
{
random[i] = tmp;
i++;
temp[tmp / y + 1, tmp % y + 1] = 1;
}
}
matrixMines = (int[,])temp.Clone(); for (int i = 1; i <= x; i++)
{
for (int j = 1; j <= y; j++)
{
matrixAround[i, j] = temp[i-1, j-1] + temp[i-1, j] + temp[i-1, j+1] + temp[i, j-1] + temp[i, j+1] + temp[i+1, j-1] + temp[i+1, j] + temp[i+1, j+1];
}
}
}
}
当赋值(100,100)的时候直接嗝屁。
不懂如何释放资源,求解。
我电脑4G内存,xp。
做扫雷大家有什么其他好的思路也请不吝赐教。class Mine
{
public static int[,] matrixMines = null;//雷分布矩阵
public static int[,] matrixDigged = null;//当前位置是否点击过矩阵
public static int[,] matrixAround = null;//当前位置周围八个点的雷的总数 public Mine()
{
} public void FreshMines(byte x,byte y)
{
int[,] temp = new int[x+2,y+2];
matrixAround = (int[,])temp.Clone();
matrixDigged = (int[,]) temp.Clone(); Random r =new Random();
int[] random = new int[x * y * (r.Next(10,15)) / 100];
for (int i = 0; i < random.Length; i++)
{
random[i] = -1;
}
for (int i = 0; i < random.Length; )
{
int tmp = r.Next(0, x*y-1);
if (!random.Contains(tmp))
{
random[i] = tmp;
i++;
temp[tmp / y + 1, tmp % y + 1] = 1;
}
}
matrixMines = (int[,])temp.Clone(); for (int i = 1; i <= x; i++)
{
for (int j = 1; j <= y; j++)
{
matrixAround[i, j] = temp[i-1, j-1] + temp[i-1, j] + temp[i-1, j+1] + temp[i, j-1] + temp[i, j+1] + temp[i+1, j-1] + temp[i+1, j] + temp[i+1, j+1];
}
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货