Important: The information in this document is obsolete and should not be used for new development.
ReadPartialResource
You can use theReadPartialResource
procedure 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
TheReadPartialResource
procedure reads the resource subsection identified by thetheResource
,offset
, andcount
parameters into a buffer specified by thebuffer
parameter. Your application is responsible for the buffer's memory management. You cannot use theReleaseResource
procedure to release the memory the buffer occupies.The
ReadPartialResource
procedure always tries to read resources from disk. If a resource is already in memory, the Resource Manager still reads it from disk, and theResError
function returns the result coderesourceInMemory
. If you try to read past the end of a resource or the value of theoffset
parameter is out of bounds,ResError
returns the result codeinputOutOfBounds
. If the handle in the parametertheResource
doesn't refer to a resource in an open resource fork,ResError
returns the result coderesNotFound
.When using partial resource routines, you should call the
SetResLoad
procedure, specifyingFALSE
for theload
parameter, before you callGetResource
. Using theSetResLoad
procedure prevents the Resource Manager from reading the entire resource into memory. Be sure to restore the normal state by callingSetResLoad
again, with theload
parameter set toTRUE
, immediately after you callGetResource
. Then useReadPartialResource
to 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
BlockMove
instead of theReadPartialResource
procedure. If you read a partial resource into memory and then change its size, you can useSetResourceSize
to change the entire resource's size on disk as necessary.SPECIAL CONSIDERATIONS
TheReadPartialResource
procedure 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 forReadPartialResource
are
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 theResError
function as described on page 1-47.For an example of the use of the
ReadPartialResource
procedure, see Listing 1-12 on page 1-35.For descriptions of the
GetResource
,SetResLoad
, andReleaseResource
routines, see page 1-68, page 1-74, and page 1-101, respectively. For a description of theSetResourceSize
procedure, see page 1-109.For information about the Memory Manager procedure
BlockMove
, see Inside Macintosh: Memory.