|
|
|
|
| Article ID: 4603 Category: IDL |
| |
IDL 8.0 : Unable to allocate memory
Published on 07/14/2010 |
| |
 |
|
Topic:
The purpose of this tech tip is to provide a few IDL 8.0 tips and tricks for avoiding memory allocation problems on 32bit operating systems, or 64bit systems with limited system memory. IDL 8.0 provides new tools to help manage memory which allow for more efficient IDL code and allow the IDL programmer to better allocate and de-allocate memory for IDL variables. Specifically, the goal is to avoid errors such as this:
| % Unable to allocate memory: to make array. |
| *Note: On modern 64bit systems, it is usually possible to install a much larger quantity of RAM, much more than 4GB. Therefore this problem can be greatly reduced or even eliminated by running IDL on a 64bit system. You are far less likely to run into this problem on a 64bit system with more than 4GB of RAM. |
Discussion:
32bit Windows systems (and other operating systems) have a maximum of 4GB system memory, or RAM, that can be installed. This greatly limits the amount of memory available to you when running applications such as IDL. For more information on Windows memory allocation and fragmentation, refer to Help Article # 3346. As Help Article # 3346 mentions, the memory available to IDL is much less than the total available memory due to the way in which MS Windows handles the memory.
32bit Windows Users
32bit Windows users in particular may notice a reduced amount of RAM that can be allocated for an array. If this is encountered follow the steps below to increase the amount of RAM available to the IDL session:
1. Open this file in a plain text editor:
| C:\Program Files\ITT\IDL\IDL80\bin\bin.x86\idlde.ini |
2. Change the file to look like the following, containing only these lines:
-vm
C:\Program Files\ITT\IDL\IDL80\bin\bin.x86\jre\bin
-vmargs
-Xms128M
-Xmx128M |
This will increase the available memory to IDL. You may also see good results by removing all but the first two lines to look like this:
-vm
C:\Program Files\ITT\IDL\IDL80\bin\bin.x86\jre\bin |
Other workarounds for All platforms
IDL 8.0 provides new tools which help to clean up unneeded variables from memory, which will allow your program to execute more efficiently and reduce memory allocations issues.
!null
The !null system variable was introduced in IDL 8.0 to allow users to either set a variable equal to null, or to destroy objects or other types of data. !null essentially allows the programmer to un-define an IDL variable, freeing up the memory that it occupies. This will allow users to destroy variables they don't need, freeing up memory for other variables to be created. For example a user could do the following:
Array = findgen(1000,1000) ;Create an array
newArray= Array^2 ;Use the array in a calculation
Array = !null ;Set the array equal to null |
Now Array is undefined, and only newArray is left in memory, leaving open memory for new variables to be created. !null can also be used to destroy objects and pointers. The !null variable can be used at any point in your program like so:
;sets a variable equal to null
Variable = !null
Or
;sets the output of the function to null
!null = functionname() |
Automatic Garbage Collection
Starting with IDL 8.0, IDL now features Automatic Garbage Collection. When a heap variable becomes inaccessible with no existing references to it, IDL will automatically de-allocate the memory it occupies, freeing it up for IDL to later use. For example, if you do something like this:
pro myprogram
p = ptr_new( findgen(1000) )
end |
when the program is finished executing, p is lost and then IDL will then remove the heap variable, the 1000 element float array in this case, from memory. Prior to IDL 8.0, when either a pointer or an object reference was lost the pointer p would be lost, out of scope, but the heap variable would remain in memory, inaccessible and therefore not usable thus needlessly taking up memory space.
However, in IDL 8.0, as soon as there are no more references to the heap variable (pointers, variable names, etc.) IDL removes the heap variable from memory, giving it back to the system for later use.
Automatic Garbage Collection is enabled by default, so there is no need to configure it. It can also be disabled/enabled at will by the use of the HEAP_REFCOUNT() function, see the IDL Help document for details.
IDL_IDLBridge
The IDL_IDLBridge object class can be used to create a spawned separate IDL session, which will have its own memory space. This will allow you to run an IDL program outside of the parent IDL Workbench session, potentially giving you more memory to work with. For example, to execute a procedure called "myprogram" with a parameter called "par" within the IDL_IDLBridge session, you could do something like this:
osession = IDL_IDLBridge()
osession.execute, 'myprogram, par' |
The string given to the IDL_IDLBridge::Execute method can be any IDL statement that you wish to be executed. This session will remain open until the IDL_IDLBridge object is destroyed. For more information search for "IDL_IDLBridge" in the IDL Help browser.
IDL Command Line
The command line version of IDL generally will have more memory available to it because it does not have to create a graphical user interface. A GUI takes up memory when it is created and rendered to the screen. Running the command line version of IDL avoids this memory overhead, which will potentially allow you more memory for your IDL program. If your IDL program consumes a lot of memory, you could create and edit the application in the Workbench, but then run the program from the command line version. This would allow you to have the development features of the workbench, while then allowing you more memory when executing your program.
The command line version of IDL 8.0 can be accessed as follows:
- Windows: Selecting the "IDL 8.0" > "Tools" > "IDL command line" start menu item.
- MacOS: Double clicking on the "IDLCommandLine.app" in the /Applications/itt/idl/idl80 directory.
- Linux/Unix: Issuing the "idl" command at a terminal prompt.
|
|
|
|
|
Printer friendly format:
Rating:
|
|
|
|
|
|