Legacy Documentclose button

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

Previous Book Contents Book Index Next

Inside Macintosh: More Macintosh Toolbox /
Chapter 1 - Resource Manager / Resource Manager Reference
Resource Manager Routines / Reading and Writing Partial Resources


SetResourceSize

You can use the SetResourceSize procedure to change the size of a resource on disk. This procedure is normally used only with ReadPartialResource and WritePartialResource.

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 use ReadPartialResource 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 call SetResourceSize 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 call WritePartialResource 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 calling GetResource or related routines, then use SetResourceSize successfully to set the resource size on disk, and finally attempt to write the resource to disk using UpdateResFile or WriteResource. 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 the ResError 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 code resourceInMemory, 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
The SetResourceSize 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 for SetResourceSize are
Trap macroSelector
_ResourceDispatch$7003

RESULT CODES
noErr0No error
resourceInMemory-188Resource already in memory
writingPastEnd-189Writing past end of file
SEE ALSO
To check for errors, call the ResError function as described on page 1-47.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
6 JUL 1996