May 98 - Tips
Volume Number: 14 (1998)
Issue Number: 5
Column Tag: Tips & Tidbits
May 98 - Tips & Tidbits
by Steve Sisak
Reducing CodeWarrior Disk Usage
Codewarrior is a product of many thousands of tiny files.
On a 2GB disk, each individual file will take up a minimum of 62k (even if it only contains a few bytes) because of the way HFS breaks up a disk. (HFS+ solves this problem, but until then...)
You could reformat your hard drive and create a smaller partition just for Codewarrior, but there is an easier way: Use Disk Copy 6.1.3 to make a 200 MB read/write disk image of an empty folder. (Actual size will need to be varied depending on what features you are installing.)
Mount the image to the desktop, install Codewarrior to the virtual volume, and then put the resulting image (or an alias to it) in your startup items folder.
Because you are working with a smaller 'virtual volume' your block size will be reduced to around 6k per file, saving you tonnes of disk space.
Colin Foster,
cfoster@pobox.com
Wrapper for ParamText
Many people don't seem to realize that you can't pass nil arguments to ParamText. Here's a wrapper routine that lets you forget about this inconvenience, as well as about having to convert between Pascal- and C-string formats:
void ParamCText
(
char *Param0,
char *Param1,
char *Param2,
char *Param3
)
{
static Str255 Param[4];
#define CopyArg(n) \
if (Param##n != nil) \
{ \
strncpy((char *) Param[n], Param##n, 255); \
Param[n][255] = 0; \
c2pstr((char *) Param[n]); \
} \
else \
{ \
Param[n][0] = 0; \
} /*if*/
CopyArg(0)
CopyArg(1)
CopyArg(2)
CopyArg(3)
ParamText(Param[0], Param[1], Param[2], Param[3]);
} /*ParamCText*/
Just a couple of notes about the code:
- The local "Param" is declared static to minimize stack usage. But feel free to change this if you don't like it.
- The strings are copied using strncpy, instead of strcpy. This way, if you pass a string longer than 255 bytes, it will be truncated, rather than inadvertently writing over random memory. strcpy should probably be banned -- did you know that something like 90% of of the Unix security bugs that people keep finding on the Internet are caused by buffer overruns?
Lawrence D'Oliveiro,
ldo@geek-central.gen.nz
TCL SetItem Gotcha
Because of an obscure gotcha in the MenuManager routine SetItem, TCL users implementing 'Other Size..." support must beware. The traditional approach reserves one item on the size menu to dynamically display the 'other' size, but this item has no logical initial value, so the temptation is to leave it empty.
In a TCL application one uses "#-1" as the text, and the #-1 is stripped by the CBartender before it calls SetItem to install the text, which in that case would be void, with dire 'unpredictable' results. Instead you can use a blank as a placeholder, ie " #-1".
Dana S Emery,
demery@ieaccess.net