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. TheGetResource
andGet1Resource
functions get a resource specified by a resource type and a resource ID. TheGetNamedResource
andGet1NamedResource
functions get a resource specified by name. TheRGetResource
function searches the ROM-resident resources as well as the open resource forks.The
SetResLoad
procedure enables and disables automatic loading of resource data into memory for routines that return handles to resources, and theLoadResource
procedure reads resource data into memory for a purged resource or after you've calledSetResLoad
with theload
parameter 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
ResLoad
isTRUE
, 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 calledSetResLoad
with theload
parameter set toFALSE
and the resource data isn't already in memory, and then you call theGetResource
function (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 callSetResLoad
with theload
parameter 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 theLoadResource
procedure.
Subtopics
- GetResource
- Get1Resource
- GetNamedResource
- Get1NamedResource
- RGetResource
- SetResLoad
- LoadResource