Important: The information in this document is obsolete and should not be used for new development.
ReadPartialResource
You can use theReadPartialResourceprocedure to read part of a resource into memory and work with a small subsection of a large resource.
PROCEDURE ReadPartialResource (theResource: Handle; offset: LongInt; buffer: UNIV Ptr; count: LongInt);
theResource- A handle to a resource.
offset- The beginning of the resource subsection to be read, measured in bytes from the beginning of the resource.
buffer- A pointer to the buffer into which the partial resource is to be read.
count- The length of the resource subsection.
DESCRIPTION
TheReadPartialResourceprocedure reads the resource subsection identified by thetheResource,offset, andcountparameters into a buffer specified by thebufferparameter. Your application is responsible for the buffer's memory management. You cannot use theReleaseResourceprocedure to release the memory the buffer occupies.The
ReadPartialResourceprocedure always tries to read resources from disk. If a resource is already in memory, the Resource Manager still reads it from disk, and theResErrorfunction returns the result coderesourceInMemory. If you try to read past the end of a resource or the value of theoffsetparameter is out of bounds,ResErrorreturns the result codeinputOutOfBounds. If the handle in the parametertheResourcedoesn't refer to a resource in an open resource fork,ResErrorreturns the result coderesNotFound.When using partial resource routines, you should call the
SetResLoadprocedure, specifyingFALSEfor theloadparameter, before you callGetResource. Using theSetResLoadprocedure prevents the Resource Manager from reading the entire resource into memory. Be sure to restore the normal state by callingSetResLoadagain, with theloadparameter set toTRUE, immediately after you callGetResource. Then useReadPartialResourceto read a portion of the resource into a buffer.
- Note
- If the entire resource is in memory and you want only part of its data, it's faster to use the Memory Manager procedure
BlockMoveinstead of theReadPartialResourceprocedure. If you read a partial resource into memory and then change its size, you can useSetResourceSizeto change the entire resource's size on disk as necessary.![]()
SPECIAL CONSIDERATIONS
TheReadPartialResourceprocedure may move or purge memory blocks in the application heap. Your application should not call this procedure at interrupt time.ASSEMBLY-LANGUAGE INFORMATION
The trap macro and routine se.lector forReadPartialResourceare
Trap macro Selector _ResourceDispatch $7001 RESULT CODES
noErr 0 No error resourceInMemory -188 Resource already in memory inputOutOfBounds -190 Offset or count out of bounds resNotFound -192 Resource not found SEE ALSO
To check for errors, call theResErrorfunction as described on page 1-47.For an example of the use of the
ReadPartialResourceprocedure, see Listing 1-12 on page 1-35.For descriptions of the
GetResource,SetResLoad, andReleaseResourceroutines, see page 1-68, page 1-74, and page 1-101, respectively. For a description of theSetResourceSizeprocedure, see page 1-109.For information about the Memory Manager procedure
BlockMove, see Inside Macintosh: Memory.