[comp.sys.mac.programmer] Init and File Manager questions

mikeoro@hubcap.clemson.edu (Michael K O'Rourke) (11/20/89)

I have two questions:

1) I have a memory resident init.  I know that if i allocate memory for a
   variable then i must set the zone to syszone or else there is a good
   chance the memory will fly away suddenly.  But if i do a normal variable 
   that is global (i am in LSC) will that variable be okay and be allocated 
   properly int he system heap?  I do have the sysheap bit set for the init
   resource.

2) I have an installer program and it copies resources from itself to the
   chosen system file.  However, when it copies the resources, it loses
   the settings for sysheap, bundle, locked, etc.   Is this normal?  Do i
   actually have to set all that again after copying?  If so, that is a
   roayl pain....


Thanx,
Michael O'Rourke

tim@hoptoad.uucp (Tim Maroney) (11/22/89)

In article <7126@hubcap.clemson.edu> mikeoro@hubcap.clemson.edu (Michael
K O'Rourke) writes:
>1) I have a memory resident init.  I know that if i allocate memory for a
>   variable then i must set the zone to syszone or else there is a good
>   chance the memory will fly away suddenly.  But if i do a normal variable 
>   that is global (i am in LSC) will that variable be okay and be allocated 
>   properly int he system heap?  I do have the sysheap bit set for the init
>   resource.

I think so, but be sure to DetachResource on your INIT.  And of course,
I'm sure you already know about the SetUpA4/RestoreA4 business.  As far
as I can tell, code resource globals for THINK C reside at the end of
the resource itself, which is grown during the make process to have
enough room.

>2) I have an installer program and it copies resources from itself to the
>   chosen system file.  However, when it copies the resources, it loses
>   the settings for sysheap, bundle, locked, etc.   Is this normal?  Do i
>   actually have to set all that again after copying?  If so, that is a
>   roayl pain....

Yes, you have to do a GetResAttrs on the old resource, and SetResAttrs
on the new one.  Since the only way to copy a resource is by doing an
AddResource, the system has no way of knowing what flags to set in the
new resource, so it sets them to defaults.

Please note, however, that it is very naughty to touch the system
file.  The INIT 31 mechanism should make it unneccessary.  If you have
to access resources from your INIT resource, then do it by opening the
reosurce file when you need them.  You can only access them at the
synchronous level anyway, so the OpenResFile/CloseResFile shouldn't
cause problems.  I think touching the system file, for anything but
Apple utilities, has been expressly forbidden for some time.
-- 
Tim Maroney, Mac Software Consultant, sun!hoptoad!tim, tim@toad.com

"`Truth' never set anyone free.  It is only *doubt* which will bring
 mental emancipation."
        -- Anton LaVey, quoted by Arthur Lyons, SATAN WANTS YOU