![]() |
Adobe Photoshop SDK |
|
Memory Management StrategiesSections on this PageIn most cases, the first action a plug-in takes is to negotiate with Photoshop for memory. Other plug-in hosts may not support the same memory options. Negotiating Space with PhotoshopThe negotiation begins, in most plug-ins, when Photoshop sets themaxData field of the pluginParamBlock to indicate the maximum number of bytes it can to free up. The plug-in then has the option of reducing this number. Reserving memory by reducing maxData can speed up most plug-in operations. Requesting the maximum amount of memory for the plug-in requires Photoshop to move all current image data out of of RAM and into its virtual memory file. This allows the plug-in to run from RAM as much as possible.
For Filter modules, which use
If your plug-in’s memory requirements are small — if it can process the image data in pieces, or if the image size is small — only reduce
One strategy is to divide If performance is a concern, you may want to perform quantitative tests of your plug-in module to compare different memory strategies. maxSpace vs. bufferSpace on Mac OSPhotoshop has a couple different mechanisms for reserving memory. There are also mechanisms for reporting available memory. Together, they allow you to calculate what sort of processing parameters you will need to use, such as chunk sizes, etc. This section is designed to detail two specific fields that indicate available space:maxSpace and bufferSpace , from the Filter parameter block.
The amount of free space available in the Mac OS heap is returned in
Photoshop sets aside an area of memory, called the linear bank. The Mac OS sets aside an area of memory for the application, called the heap space. BufferSpaceProc() in the Buffer suite, and FilterRecord::bufferSpace return the amount of space available in the linear bank, or the heap space if the linear bank is not present. This memory is available via the Buffer suite.
Neither
Using Buffer and Handle SuitesBuffer SuiteThe Buffer Suite Callbacks provides a mechanism for a plug-in to allocate and dispose of memory from the pool of Photoshop memory. This mechanism allows for the most optimal way for Photoshop and the plug-in to share memory, and allows you to tune the memory use of your plug-in to optimize performance.
Previous versions of the plug-in specification provide a simple mechanism for interacting with the Photoshop virtual memory system by letting a plug-in specify a certain amount of memory which the host should reserve for the plug-in. This communication is done through the
This approach has two problems. First, the memory is reserved throughout the execution of the plug-in. Second, the plug-in may still run up against limitations imposed by the host. For example, Photoshop 2.5 will, in large memory configurations, allocate most of memory at startup via a
If a plug-in module allocates a lot of memory using For most types of plug-ins, buffer allocations can be delayed until they are actually needed. Unfortunately, Export modules must track the buffer for the data requested from the host even though the host allocates the buffer. This means that the Buffer suite routines do not provide much help for Export modules.
Handle Suite In general, the Buffer suite routines are more effective for memory allocation than the Handle suite. The Buffer suite may have access to memory unavailable to the Handle suite. You should use the Handle suite, however, if the data you are managing is a Mac OS handle. Although you can allocate handles directly using the Mac OS Toolbox, these callbacks are recommended, instead. When you use these callbacks, Photoshop accounts for these handles in its virtual memory space calculations. |