Dynamic Memory Allocation


Fortran allows you to dynamically allocate memory for arrays using the ALLOCATE statement. Any allocated memory can be deallocated using the DEALLOCATE statement. Dynamic memory allocation is useful if the size of an array won't be known until runtime in that you don't have to declare a really large array to take care of all possibilities. Dynamic memory allocation can also be dangerous in that you must be careful to deallocate all allocated memory when it is no longer needed. If you don't, your program will have a memory leak.

Java does not support explicit dynamic memory allocation and deallocation because it has a sophisticated memory management system as part of the Java runtime. Because memory for an array can be allocated anywhere in the program, you can wait to declare the array until you know what size it will be. A system thread called the garbage collector monitors the state of your program and automatically deallocates memory for objects that are no longer being used.



Technical Java. Applications for Science and Engineering
Technical Java: Applications for Science and Engineering
ISBN: 0131018159
EAN: 2147483647
Year: 2003
Pages: 281
Authors: Grant Palmer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net