Important: The information in this document is obsolete and should not be used for new development.
Working With Partial Resources
Some resources, such as the'snd '
and'sfnt'
resources, can be quite large--sometimes too large to fit in the available memory. TheReadPartialResource
andWritePartialResource
procedures, which are available in System 7 and later versions of system software, allow you to read a portion of the resource into memory or alter a section of the resource while it is still on disk. You can also use theSetResourceSize
procedure to enlarge or reduce the size of a resource on disk. When you useReadPartialResource
andWritePartialResource
, you specify how far into the resource you want to begin reading or writing and how many bytes you actually want to read or write at that spot, so you must be sure of the location of the data.
To read or write any part of a resource, call the
- WARNING
- Be aware that having a copy of a resource in memory when you are using the partial resource routines may cause problems. For example, if you read the resource into memory using
GetResource
, modify the resource in memory, and then access the resource on disk using either theReadPartialResource
orWritePartialResource
procedure, note that these procedures work with the data in the buffer you specify, not the data referenced through the resource's handle.SetResLoad
procedure specifyingFALSE
for itsload
parameter, then use theGetResource
function to get an empty handle (that is, a handle whose master pointer is set toNIL
) to the resource. (Because of the call to theSetResLoad
procedure, theGetResource
function does not load the entire resource into memory.) Then callSetResLoad
specifyingTRUE
for itsload
parameter and use the partial resource routines to access portions of the resource.Listing 1-12 illustrates one way to deal with partial resources. The application-defined procedure
MyReadAPartial
begins by callingSetResLoad
(with theload
parameter set toFALSE
) to ensure that the Resource Manager will not attempt to read the entire resource into memory in the subsequent call toGetResource
. After callingGetResource
and checking for errors,MyReadAPartial
callsSetResLoad
(with theload
parameter set toTRUE
) to restore normal loading of resource data into memory. The procedure then callsReadPartialResource
, specifying as parameters the handle returned byGetResource
, an offset to the beginning of the resource subsection to be read, a buffer into which to read the subsection, and the length of the subsection. TheReadPartialResource
procedure reads the specified partial resource into the specified buffer.Listing 1-12 Using partial resource routines
PROCEDURE MyReadAPartial(myRsrcType: ResType; myRsrcID: Integer; start: LongInt; count: LongInt; VAR putItHere: Ptr); VAR myResHdl: Handle; myErr: OSErr; BEGIN SetResLoad(FALSE); {don't load resource} myResHdl := GetResource(myRsrcType, myRsrcID); myErr := ResError; SetResLoad(TRUE); {reset to always load} IF myErr = noErr THEN BEGIN ReadPartialResource(myResHdl, start, putItHere, count); myErr := ResError; {check and report error} IF myErr <> noErr THEN DoError(myErr); END ELSE {handle error from GetResource} DoError(myErr); END;