?? memory.html
字號:
<HTML><HEAD><TITLE>Newmat09 - memory management</TITLE></HEAD><BODY><H2>Memory management</H2><A HREF="efficien.html"> next</A> - <A HREF="efficien.html"> skip</A> - <A HREF="refer.html"> up</A> - <A HREF="index.html"> start</A><P>The package does not support delayed copy. Several strategies arerequired to prevent unnecessary matrix copies.<P>Where a matrix is called as a function argument use a constantreference. For example<PRE> YourFunction(const Matrix& A)</PRE>rather than<PRE> YourFunction(Matrix A)</PRE><P>Skip the rest of this section on your first reading.<HR><B>Gnu g++ (< 2.6) users please read on; if you are returning matrix valuesfrom a function, then you must use the ReturnMatrix construct.</B> <HR><P>A second place where it is desirable to avoid unnecessary copies is whena function is returning a matrix. Matrices can be returned from afunction with the return command as you would expect. However these mayincur one and possibly two copyings of the matrix. To avoid this use thefollowing instructions.<P>Make your function of type ReturnMatrix . Then precede the returnstatement with a Release statement (or a ReleaseAndDelete statement ifthe matrix was created with new). For example<PRE> ReturnMatrix MakeAMatrix() { Matrix A; // or any other matrix type ...... A.Release(); return A; }</PRE>or<PRE> ReturnMatrix MakeAMatrix() { Matrix* m = new Matrix; ...... m->ReleaseAndDelete(); return *m; }</PRE>If your compiler objects to this code, replace the return statements with<PRE> return A.ForReturn();</PRE>or<PRE> return m->ForReturn();</PRE>If you are using AT&T C++ you may wish to replace <TT>return A;</TT> byreturn <TT>(ReturnMatrix)A;</TT> to avoid a warning message; but this willgive a runtime error with Gnu. (You can't please everyone.)<HR><B>Do not forget to make the function of type ReturnMatrix; otherwiseyou may get incomprehensible run-time errors.</B> <HR>You can also use <TT>.Release()</TT> or <TT>->ReleaseAndDelete()</TT>to allow a matrix expression to recycle space. Suppose you call<PRE> A.Release();</PRE>just before <TT>A</TT> is used just once in an expression. Then the memoryusedby <TT>A</TT> is either returned to the system or reused in the expression.Ineither case, <TT>A</TT>'s memory is destroyed. This procedure can be used toimprove efficiency and reduce the use of memory.<P>Use <TT>->ReleaseAndDelete</TT> for matrices created by new if you want tocompletely delete the matrix after it is accessed.<P><A HREF="efficien.html"> next</A> - <A HREF="efficien.html"> skip</A> - <A HREF="refer.html"> up</A> - <A HREF="index.html"> start</A><P></BODY></HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -