![]() |
SetResourceSize |
||||
Header: | Resources.h | Carbon status: | Supported | |
Sets the size of a resource on disk.
void SetResourceSize ( Handle theResource, SInt32 newSize );
A handle to the resource which you wish to change.
The size, in bytes, that you want the resource to occupy on disk. If the specified size is smaller than the resources 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 resources current size on disk, all data is preserved, but the additional area is uninitialized (arbitrary data).
This function is normally used only with the ReadPartialResource and WritePartialResource functions.
This function 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 you read a partial resource into memory and then change its size, you must use this function to change the entire resources 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 this function. For instance, suppose you read an entire resource into memory by calling GetResource or related functions, then use SetResourceSize successfully to set the resource size on disk, and finally attempt to write the resource to disk using the UpdateResFile or WriteResource functions. 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, this function 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.
This function may move or purge memory blocks in the application heap. Your application should not call this function at interrupt time.
Supported in Carbon. Available in Mac OS 8.1 and later when Carbon 1.0.2 or later is present.
© 2000 Apple Computer, Inc. (Last Updated 5/8/2000)