Important: The information in this document is obsolete and should not be used for new development.
SetResourceSize
You can use theSetResourceSize
procedure to change the size of a resource on disk. This procedure is normally used only withReadPartialResource
andWritePartialResource
.
PROCEDURE SetResourceSize (theResource: Handle; newSize: LongInt);
theResource
- A handle to a resource.
newSize
- The size, in bytes, that you want the resource to occupy on disk.
DESCRIPTION
Given a handle to a resource,SetResourceSize
sets the size field of the specified resource on disk without writing the resource data. You can change the size of
any resource, regardless of the amount of memory you have available.If the specified size is smaller than the resource's current size on disk, you lose any data from the cutoff point to the end of the resource. If the specified size is larger than the resource's current size on disk, all data is preserved, but the additional area is uninitialized (arbitrary data).
If you read a partial resource into memory and then change its size, you must use
SetResourceSize
to change the entire resource's size on disk as necessary. For example, suppose the entire resource occupies 1 MB and you useReadPartialResource
to read in a 200 KB portion of the resource. If you then increase the size of this partial resource to 250 KB, you must callSetResourceSize
to set the size of the resource on disk to 1.05 MB. Note that in this case you must also keep track of the resource data on disk and move any data that follows the original partial resource on disk. Otherwise, there will be no space for the additional 50 KB when you callWritePartialResource
to write the modified partial resource to disk.Under certain circumstances, the Resource Manager overrides the size you set with a call to
SetResourceSize
. For instance, suppose you read an entire resource into memory by callingGetResource
or related routines, then useSetResourceSize
successfully to set the resource size on disk, and finally attempt to write the resource to disk usingUpdateResFile
orWriteResource
. In this case, the Resource Manager adjusts the resource size on disk to conform with the size of the resource in memory.If the disk is locked or full, or the file is locked, the
SetResourceSize
procedure does nothing, and theResError
function returns an appropriate File Manager result code. If the resource is in memory, the Resource Manager tries to set the size of the resource on disk. If the attempt succeeds,ResError
returns the result coderesourceInMemory
, and the Resource Manager does not update the copy in memory. If the attempt fails,ResError
returns an appropriate File Manager result code.SPECIAL CONSIDERATIONS
TheSetResourceSize
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 selector forSetResourceSize
are
Trap macro Selector _ResourceDispatch $7003 RESULT CODES
noErr 0 No error resourceInMemory -188 Resource already in memory writingPastEnd -189 Writing past end of file SEE ALSO
To check for errors, call theResError
function as described on page 1-47.