ADC Home > Reference Library > Technical Q&As > Legacy Documents > Graphics & Imaging >

Not Recommended Documentclose button

Important: The information in this document is Not Recommended and should not be used for new development.

Current information on this Reference Library topic can be found here:

Using Temporary Memory with OpenPicture


Q: I use the OpenPicture, draw, ClosePicture sequence to create a picture handle. Since the handle can be quite large, and since I dispose of it fairly quickly, it would make sense to allocate it in temporary memory. But I haven't found any reasonable way to do that. Any suggestions? Both these situations arise because my application runs in a fairly small (800K) partition. I do this so that other applications have adequate space to work with it, since one of my main functions is to interact with other applications using Apple events. However, I occasionally need more memory for a few seconds at a time.

A: There are two ways to cause OpenPicture to use temporary memory. A simple way to do it is to allocate a block of temporary memory, then create a new heap zone in that block and make it the current zone just before you call OpenPicture. This will cause subsequent memory allocations to happen in your temporary block, and will work fine.

Another way is to replace the putPicProc, as is commonly done when spooling a picture to disk, and instead spool it to temporary memory.

You create a handle in temporary memory the size of a picture and fill in its size and picFrame fields so that it looks like a normal picture handle. In your putPicProc you copy the data in, continually resizing the handle if necessary to fit the data. After you call ClosePicture, remove your putPicProc; then you can use the temporary handle just like a normal picture.

The advantage of this method over the first one is that you can make the picture as large as temporary memory will let you, and you end up using just enough memory. The first technique, while technically easier to implement, limits you to the size of the heap you initially create, and you also may use a lot more temporary memory than you need. If you're able to come up with a good guess of how large your pictures are going to be, use the first technique; if not, use the second one. See Inside Macintosh: Memory for more information about creating heap zones.

If you're not familiar with picture spooling, see Inside Macintosh Volume V, page 89, which has code for spooling a picture to disk as it's created. This is the same technique as documented there, only it spools the picture to temporary memory instead.

[Sep 15 1995]


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.