[comp.binaries.mac] CODE Unlocker desk accessory

dplatt@coherent.com (Dave Platt) (10/25/88)

[CODE Unlocker desk accessory]

This posting contains CODE Unlocker, a desk accessory that can set or
reset the "locked" bit on CODE resources in an application.  It was
written for developers coding in LightSpeed C, but can be used with
other development systems or even without a development system (i.e.,
on completed commercial applications) if necessary.

The original version of the Segment Loader (in the 128k and 512k Macs)
required that all CODE resources be locked in the application file,
thus ensuring that the program's code would not move around in memory
during execution (and hence invalidating jump-table addresses and
stack-return addresses).  This scheme tended to cause some severe
heap-fragmentation problems, because code (once loaded) could never be
relocated when the Memory Manager tried to compact the heap.

In the 128k and 256k ROMs (and in 64k-ROM systems equipped with a patch
to the Segment Loader), most CODE resources can and should be marked as
"unlocked" in the application resource file.  The new Segment Loader
will read the CODE resources into memory, move them to the top of the
heap, and lock them there... thus keeping them out of the middle of the
heap and reducing the chances of heap fragmentation.

Some development systems permit the programmer to specify whether CODE
resources should be placed in the application file in "locked" or
"unlocked" form.  Unfortunately, LightSpeed C does not: all CODE
resources are marked "lock", thus ensuring maximum compatibility with
all Macs but leaving the application vulnerable to heap fragmentation.

The CODE Unlocker desk accessory can be used to set (lock) or reset
(unlock) the lock bits on the CODE resources in an application.  It
follows the rules in Inside Mac: the main CODE resource is not
unlocked.

If you're developing an application that you _know_ will never need to
run on a 128k or 512k Mac that might not have the Segment Loader patch,
then you can use CODE Unlocker to turn off the "lock" bits in the
application file... it's much quicker and more convenient than doing so
with ResEdit.

Note: if you've been a cautious person and installed Vaccine on your
Mac, CODE Unlocker will trigger Vaccine alerts each time it attempts to
lock or unlock a CODE resource... just as LightSpeed C does when it
writes new CODE resources into an application you're linking.  CODE
Unlocker does _not_ add new CODE resources or modify the ones in the
file... it simply twiddles the lock bit.

CODE Unlocker is "freeware": feel free to use it, pass it around, etc.
It's based on the "Generic DA" shell written by David HM Spector.

Dave Platt                                             VOICE: (415) 493-8805
  USNAIL: Coherent Thought Inc.  3350 West Bayshore #205  Palo Alto CA 94303
  UUCP: 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