MemoryConstrained
Usage
• MemoryConstrained[expr, b]用于对expr进行计算,如果该计算需要超过b字节的内存,它就停止.
• 如果内存不够,MemoryConstrained[expr, b, failexpr] 返回 failexpr.
Notes
• 如果在对expr进行计算的过程中所请求的附加内存量超过b字节,MemoryConstrained会产生一个中断来结束对expr的计算. • 只用当该计算被异常中止时,MemoryConstrained 才对failexpr进行计算. • 如果该计算被异常中止,而没有failexpr被指定,MemoryConstrained返回$Aborted. • MemoryConstrained所产生的异常中止可以被当作由Abort产生的异常中止处理,因而能被AbortProtect所控制.
Further Examples
Here is an expression that would take a lot of memory to evaluate. The constraint stops the computation and returns the string.
In[1]:=
|
Out[1]=
|
|