Important: The information in this document is obsolete and should not be used for new development.
Reading Resources Into Memory
The routines described in this section allow your application to read resource data into memory. TheGetResourceandGet1Resourcefunctions get a resource specified by a resource type and a resource ID. TheGetNamedResourceandGet1NamedResourcefunctions get a resource specified by name. TheRGetResourcefunction searches the ROM-resident resources as well as the open resource forks.The
SetResLoadprocedure enables and disables automatic loading of resource data into memory for routines that return handles to resources, and theLoadResourceprocedure reads resource data into memory for a purged resource or after you've calledSetResLoadwith theloadparameter set toFALSE.When your application requests a resource, the Resource Manager normally looks in the current resource file's resource map in memory. If it can't find an entry for the specified resource, the Resource Manager searches the resource maps for each open resource fork in the reverse order that the resource forks were opened. If it can't find an entry for the specified resource in any of these resource maps, the Resource Manager searches your application's resource map. If it can't find an entry for the specified resource in
your application's resource map, the Resource Manager searches the resource map for the System file.The Resource Manager determines whether or not to load the specified resource into memory according to the entry for that resource in the resource map. If the resource's resource map entry contains a valid handle, the Resource Manager returns that handle. If the value of the handle is
NIL, the Resource Manager reads the resource data into memory.Before reading the resource data into memory, the Resource Manager calls the Memory Manager to allocate a relocatable block for the resource data. The Memory Manager allocates the block, assigns a master pointer to the block, and returns to the Resource Manager a pointer to the master pointer. The Resource Manager then installs this handle in the resource map and also returns a handle to the resource.
If the resource's resource map entry contains an empty handle (a handle whose master pointer is set to NIL) and the value of the system global variable
ResLoadisTRUE, the Resource Manager routines that get resources reallocate the resource's handle and read the resource data from disk back into memory.
- IMPORTANT
 - In certain situations, a Resource Manager routine can return an empty handle (a handle whose master pointer is set to
 NIL). For instance, if you've calledSetResLoadwith theloadparameter set toFALSEand the resource data isn't already in memory, and then you call theGetResourcefunction (or any of the other Resource Manager routines that get a resource), the Resource Manager routine returns an empty handle (a handle whose master pointer is set toNIL). This can also happen if you read resource data for a purgeable resource into memory and then callSetResLoadwith theloadparameter set toFALSE. If the resource data is later purged, when you callGetResource(or other routines that get a resource), the Resource Manager returns an empty handle. You should test for an empty handle in these situations. To make the handle a valid handle to resource data in memory, you can call theLoadResourceprocedure.![]()
Subtopics
- GetResource
 - Get1Resource
 - GetNamedResource
 - Get1NamedResource
 - RGetResource
 - SetResLoad
 - LoadResource