2013-07-19 83 views
0

我正在处理崩溃的代码。我意识到编译后的程序在释放变量时会崩溃,但我不知道如何解决它。释放声明导致崩溃

当我运行的代码,从Windows弹出似乎说:

main.exe has stopped working. Windows can check for a solution to the problem.

和编译器显示消息Process returned -1073740940 (0xC0000374) execution time : 1.171 s

娄存在的代码示例:

Subroutine PoissonCode() 
Use Mesh 
Implicit none 
Real(8), Allocatable :: u(:,:),v(:,:),p(:,:) 
Character(50) :: Nome 
Allocate(u(0:Imax,0:jmax),v(0:Imax,0:jmax),p(0:Imax,0:jmax),fx(0:Imax,0:jmax),fy(0:Imax,0:jmax)) 
Allocate(xd(0:Imax),yd(0:Jmax)) 

........Code Here............... 

Deallocate(u,v,p,fx,fy,xd,yd) 
Deallocate(xd,yd) 

End Subroutine PoissonCode 

我把完整代码here作进一步调查。 我也尝试在Windows 7 x64和Windows XP x86中运行不同版本的GFortran的代码,但没有成功。

编辑:

代码正确的一端是:

... 

Deallocate(u,v,p,fx,fy) 
Deallocate(xd,yd) 

End Subroutine PoissonCode 

截至日期:

我测试了不同的编译器代码(英特尔视觉Fortran语言)和仍然没有成功。

+0

A **系统**崩溃?如[BSOD](http://en.wikipedia.org/wiki/Blue_Screen_of_Death)?如果不是,请不要这样声称。 – user2246674

+0

我在'deallocate'之前和之后放了'pause'语句。这让我得出结论,释放可能是崩溃的原因。 – Eleteroboltz

+0

@HighPerformanceMark:不久前我有一个类似的问题:http://stackoverflow.com/questions/17452243/stalling-at-deallocate。 –

回答

1

D'Joey:嗯(我们所有的人)

Deallocate(u,v,p,fx,fy,xd,yd) 
Deallocate(xd,yd) 

在第二行,你的程序(尝试)解除分配变量已经释放在第一线。我想有时候阅读代码是值得的。

deallocate有可选参数staterrmsg它可以用来捕捉这类错误,并提供一个替代程序崩溃的默认行为。

+0

对不起,你是对的,但是我在制定这个问题时在这里输入了错误。我原来的代码没有这个双Deallocated变量。我试图使用你提到的可选参数,但代码在我能够看到错误参数之前停止。 – Eleteroboltz

+0

好的...我发现了错误。子程序'PoissonCode'内的代码正在访问无效的数组位置。非常感谢你的帮助。 – Eleteroboltz

+0

是的,再次查看你的代码,你在子程序'PoissonSolve'中有'p(0:imax,0:imax)',但在'PoissonCode'子程序中声明了它'p(0:imax,0:jmax)' 。 –