home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / csmpdigest / csmp-digest-v3-039 < prev    next >
Text File  |  2010-09-21  |  58KB  |  1,682 lines

  1. Received-Date: Sun, 26 Jun 1994 23:31:02 +0200
  2. From: pottier@clipper.ens.fr (Francois Pottier)
  3. Subject: csmp-digest-v3-039
  4. To: csmp-digest@ens.fr
  5. Date: Sun, 26 Jun 1994 23:30:56 +0200 (MET DST)
  6. X-Mailer: ELM [version 2.4 PL23]
  7. Mime-Version: 1.0
  8. Content-Type: text/plain; charset=ISO-8859-1
  9. Content-Transfer-Encoding: 8bit
  10. Errors-To: listman@ens.fr
  11. Reply-To: pottier@clipper.ens.fr
  12. X-Sequence: 42
  13.  
  14. C.S.M.P. Digest             Sun, 26 Jun 94       Volume 3 : Issue 39
  15.  
  16. Today's Topics:
  17.  
  18.         API-headers for Control Strip Modules?
  19.         Apple Event Question
  20.         Are NewPtr() and malloc() different? (source included)
  21.         Closing Down the FINDER
  22.         Fat-stripping
  23.         Finder Comments and Finder Info Updating
  24.         MacTech's ftp site now available!
  25.         QuickDraw GX Display Devices
  26.         SEMI-SUMMARY: Reading JPEGs (with code)
  27.         VBL interrupt & Stack Sniffer
  28.         Writing dcmd with Think C (Q)
  29.  
  30.  
  31.  
  32. The Comp.Sys.Mac.Programmer Digest is moderated by Francois Pottier
  33. (pottier@clipper.ens.fr).
  34.  
  35. The digest is a collection of article threads from the internet newsgroup
  36. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  37. regularly and want an archive of the discussions.  If you don't know what a
  38. newsgroup is, you probably don't have access to it.  Ask your systems
  39. administrator(s) for details.  If you don't have access to news, you may
  40. still be able to post messages to the group by using a mail server like
  41. anon.penet.fi (mail help@anon.penet.fi for more information).
  42.  
  43. Each issue of the digest contains one or more sets of articles (called
  44. threads), with each set corresponding to a 'discussion' of a particular
  45. subject.  The articles are not edited; all articles included in this digest
  46. are in their original posted form (as received by our news server at
  47. nef.ens.fr).  Article threads are not added to the digest until the last
  48. article added to the thread is at least two weeks old (this is to ensure that
  49. the thread is dead before adding it to the digest).  Article threads that
  50. consist of only one message are generally not included in the digest.
  51.  
  52. The digest is officially distributed by two means, by email and ftp.
  53.  
  54. If you want to receive the digest by mail, send email to listserv@ens.fr
  55. with no subject and one of the following commands as body:
  56.     help                        Sends you a summary of commands
  57.     subscribe csmp-digest Your Name    Adds you to the mailing list
  58.     signoff csmp-digest            Removes you from the list
  59. Once you have subscribed, you will automatically receive each new
  60. issue as it is created.
  61.  
  62. The official ftp info is //ftp.dartmouth.edu/pub/csmp-digest.
  63. Questions related to the ftp site should be directed to
  64. scott.silver@dartmouth.edu. Currently no previous volumes of the CSMP
  65. digest are available there.
  66.  
  67. Also, the digests are available to WAIS users.  To search back issues
  68. with WAIS, use comp.sys.mac.programmer.src. With Mosaic, use
  69. http://www.wais.com/wais-dbs/comp.sys.mac.programmer.html.
  70.  
  71.  
  72. -------------------------------------------------------
  73.  
  74. >From Gordie Freedman <gordie@kaleida.com>
  75. Subject: API-headers for Control Strip Modules?
  76. Date: 8 Jun 1994 07:17:19 GMT
  77. Organization: Kaleida Labs, Inc.
  78.  
  79. Anybody know where the API is documented to write control strip modules?
  80. I also wasn't sure if there were any header files you used with this
  81. stuff, or if you had to roll your own. Thanks in advance,
  82.  
  83. Gordie Freedman
  84. --
  85.  
  86. gordie@kaleida.com - Kaleida Labs, Inc. - Mountain View, CA
  87.  
  88. +++++++++++++++++++++++++++
  89.  
  90. >From tgaul@halcyon.com (Troy Gaul)
  91. Date: Wed, 08 Jun 1994 21:42:50 -0700
  92. Organization: Infinity Systems
  93.  
  94. In article <2t3r9v$3mr@golden.kaleida.com>, Gordie Freedman
  95. <gordie@kaleida.com> wrote:
  96.  
  97. > Anybody know where the API is documented to write control strip modules?
  98. > I also wasn't sure if there were any header files you used with this
  99. > stuff, or if you had to roll your own. Thanks in advance,
  100.  
  101. They're in the PowerBook 500-series technical notes, which were included on
  102. the June Developer CD.  As far as a header file goes, I didn't see anything
  103. included.
  104.  
  105. _troy
  106. //////// //////___Troy Gaul_________________________tgaul@halcyon.com__ //
  107.   //    //       Infinity Systems ; Redmond, Washington                //
  108.  //    //  //  "Insert witty quote here."                             //
  109. //    //////________________________________________________________ //
  110.  
  111. +++++++++++++++++++++++++++
  112.  
  113. >From jonpugh@netcom.com (Jon Pugh)
  114. Date: Sat, 11 Jun 1994 09:12:12 GMT
  115. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  116.  
  117. Gordie Freedman (gordie@kaleida.com) wrote:
  118. > Anybody know where the API is documented to write control strip modules?
  119. > I also wasn't sure if there were any header files you used with this
  120. > stuff, or if you had to roll your own. Thanks in advance,
  121.  
  122. For that matter, can you get the software any way without buying a 500?
  123.  
  124. Not that I don't want a 500...
  125.  
  126. Jon
  127.  
  128. +++++++++++++++++++++++++++
  129.  
  130. >From tgaul@halcyon.com (Troy Gaul)
  131. Date: Sat, 11 Jun 1994 22:46:33 -0700
  132. Organization: Infinity Systems
  133.  
  134. In article <jonpughCr86wC.LBA@netcom.com>, jonpugh@netcom.com (Jon Pugh)
  135. wrote:
  136.  
  137. > Gordie Freedman (gordie@kaleida.com) wrote:
  138. > > Anybody know where the API is documented to write control strip modules?
  139. > > I also wasn't sure if there were any header files you used with this
  140. > > stuff, or if you had to roll your own. Thanks in advance,
  141. > For that matter, can you get the software any way without buying a 500?
  142. > Not that I don't want a 500...
  143.  
  144. I tried a copy of Control Strip, grabbed off the hard drive of a 500, and
  145. tried it on a desktop Mac, and it wouldn't function, but it worked fine on
  146. a PowerBook 140.  
  147.  
  148. I certainly hope that they allow it to work on desktop Macs as well soon. 
  149. I'd like to use it for a few things myself (like volume and monitor
  150. depth-switching), and its modular architecture makes it easy for third
  151. parties to write modules that would be useful for users of desktop
  152. machines.
  153.  
  154. _troy
  155. //////// //////___Troy Gaul_________________________tgaul@halcyon.com__ //
  156.   //    //       Infinity Systems ; Redmond, Washington                //
  157.  //    //  //  "Insert witty quote here."                             //
  158. //    //////________________________________________________________ //
  159.  
  160. +++++++++++++++++++++++++++
  161.  
  162. >From quinn@cs.uwa.edu.au (Quinn "The Eskimo!")
  163. Date: Sun, 12 Jun 1994 14:54:34 +0800
  164. Organization: Department of Computer Science, The University of Western Australia
  165.  
  166. In article <jonpughCr86wC.LBA@netcom.com>, jonpugh@netcom.com (Jon Pugh) wrote:
  167.  
  168. >For that matter, can you get the software any way without buying a 500?
  169.  
  170. Yes.  Get a 280 (:
  171. -- 
  172. Quinn "The Eskimo!"      <quinn@cs.uwa.edu.au>     "Support HAVOC!"
  173. Department of Computer Science, The University of Western Australia
  174.  
  175. +++++++++++++++++++++++++++
  176.  
  177. >From quinn@cs.uwa.edu.au (Quinn "The Eskimo!")
  178. Date: Sun, 12 Jun 1994 23:08:17 +0800
  179. Organization: Department of Computer Science, The University of Western Australia
  180.  
  181. In article <tgaul-110694224633@bellevue-ip68.halcyon.com>,
  182. tgaul@halcyon.com (Troy Gaul) wrote:
  183.  
  184. >I tried a copy of Control Strip, grabbed off the hard drive of a 500, and
  185. >tried it on a desktop Mac, and it wouldn't function, but it worked fine on
  186. >a PowerBook 140.  
  187.  
  188. The guys at the WWDC session said they would consider moving it to the
  189. desktop Macs depending on how it was received on the PowerBooks. 
  190. Personally I think it's a TOE (Thing Of Evil (tm)).  That won't stop me
  191. using it of course (:
  192. -- 
  193. Quinn "The Eskimo!"      <quinn@cs.uwa.edu.au>     "Support HAVOC!"
  194. Department of Computer Science, The University of Western Australia
  195.   Now if only the 280C I have on order would arrive ):
  196.  
  197. ---------------------------
  198.  
  199. >From jml16@po.CWRU.Edu (Jonathon M. Lipsky)
  200. Subject: Apple Event Question
  201. Date: 2 Jun 1994 20:01:16 GMT
  202. Organization: Case Western Reserve University, Cleveland, Ohio (USA)
  203.  
  204.  
  205. I would like to know if anyone has created their own
  206. AppleEvents to pass data between two programs.  What
  207. I would like to do is impliment an event similar to
  208. an OpenDocument, but I would like to pass a string
  209. that the recieving program that would give it the
  210. needed information.  All of my attempts at implimenting
  211. this have not succeeded, so any examples would be
  212. greatly appreciated.
  213.  
  214. Jon Lipsky (jml16@po.cwru.edu)
  215.  
  216. +++++++++++++++++++++++++++
  217.  
  218. >From Here@There (Someone)
  219. Date: 10 Jun 1994 17:29:50 GMT
  220. Organization: Large Fuzzy Room
  221.  
  222. There's lots of samples around, adapting a 'real' AppleEvent to your
  223. private needs will be easiest.  Here's one way you might want to implement
  224. the send and recieve functions (VERY simple here)
  225.  
  226. // a coupla defines
  227. #define kMyPrivateEventClass 'MYEV'
  228. #define kOpenFileStringEvent 'OPFS'
  229. #define typeMyPString 'MPST'
  230. // Get the address (through PPCBrowser or elsewhere) and the 
  231. // file string and pass them in
  232. OSErr SendFileNameString(ConstStr255 theFullPath,AEDesc * theAddress)
  233. {
  234. AppleEvent theEvent;
  235. OSErr theError = noErr;
  236. // create the event
  237. theError = AECreateAppleEvent(kMyPrivateEventClass,kOpenFileStringEvent,
  238. theAddress,kAutoGenerateReturnID,kAnyTransactionID,&theEvent);
  239. // if no error, add our string
  240. if(theError == noErr)
  241. theError=
  242. AEPutParamPtr(&theEvent,keyDirectObject,typeMyPString,(Ptr)&theFullPath[1],theFullPath[0]);
  243. // send the event
  244. if(theError == noErr)
  245. theError =
  246. AESend(&theEvent,nil,kAENoReply,kAENormalPriority,kAEDefaultTimeout,(IdleProcPtr)
  247. nil,nil);
  248.  
  249. return( theError );
  250. }
  251.  
  252.  
  253. // and on the recieving end, get the thing out
  254.  
  255. pascal OSErr HandleMyOpenFileStr(AppleEvent *messagein, AppleEvent *reply,
  256. long refIn)
  257. {OSErr theError = noErr;
  258. Str255 fileString;
  259. DescType returnedType;
  260. Size returnedSize;
  261. // get the string from the event
  262. theError = AEGetParamPtr(messagein,   // from this event
  263.                            keyDirectObject,    // get the direct object
  264.                            typeMyPString,       // as a pstring
  265.                            &returnedType,     
  266.                            (Ptr)&fileString[1],  // put it here
  267.                            254,      // max size
  268.                            &returnedSize);
  269. if(theError == noErr){
  270. fileString[0] = returnedSize;
  271. theError  = FSOpen(fileString, nil,&fileRefNum);
  272. // fileRefNum is somewhere, whereever you need it
  273. }
  274. return ( theError);
  275. }
  276.  
  277. ---------------------------
  278.  
  279. >From cr@cs.strath.ac.uk (Chris Reid)
  280. Subject: Are NewPtr() and malloc() different? (source included)
  281. Date: Mon, 06 Jun 1994 12:15:52 +0000
  282. Organization: University of Strathclyde
  283.  
  284. Hi everybody,
  285.  
  286. I have written some code that implements Radix Sort (it sorts
  287. an array of longs in linear time). It seems to work well enough,
  288. but one thing is really strange: when I replace the NewPtr()
  289. calls with calls to malloc(), the corresponding free() doesn't seem
  290. to work. Here's roughly what happens:
  291.  
  292.  
  293. // RadixSort implemented using NewPtr() and DisposPtr()
  294.  
  295. mem = FreeMem();    // We've got amount 'mem' bytes in the heap
  296. RadixSort(someArray, numItems);    // Do the sorting
  297. waste = mem - FreeMem();    // Is there a memory leak?
  298.  
  299. waste is always zero (just as it should be), BUT:
  300.  
  301. // RadixSort implemented using malloc() and free()
  302.  
  303. mem = FreeMem();    // We've got amount 'mem' bytes in the heap
  304. RadixSort(someArray, numItems);    // Do the sorting
  305. waste = mem - FreeMem();    // Is there a memory leak?
  306.  
  307. waste is non-zero, a very disturbing fact. But it gets even better,
  308. because on consecutive calls, waste IS zero. It looks as if
  309. malloc() remebers what it's done before. By the way, I need to
  310. use malloc() because the code has to be (sort of) platform independent.
  311.  
  312. The source is attached (hence the cross-posting to alt.sources.mac).
  313. It works, so feel free to use it. Something must be going wrong somewhere,
  314. I can't see it, can anybody else? I'm using THINK C 6.0.1 with Objects.
  315.  
  316. Thanks in advance folks!
  317.  
  318.  
  319. Chris
  320.  
  321. PS: a description of Radix Sort can be found in almost any books on
  322. algorithms
  323.  
  324. /********** Radix Sort Source *************************/
  325.  
  326. #define MAC
  327.  
  328. #ifdef MAC
  329. #define BYTE0 3
  330. #define BYTE1 2
  331. #define BYTE2 1
  332. #define BYTE3 0
  333. #endif
  334.  
  335. // for PC's or any other Big Endian...
  336. #ifdef PC
  337. #define BYTE0 0
  338. #define BYTE1 1
  339. #define BYTE2 2
  340. #define BYTE3 3
  341. #endif
  342.  
  343. #define kNumElements    500        // allocate space for 500 longs at a time
  344. #define kNumPasses        4                    // 32 bit longs - split into 4 * 8 bits
  345. #define kNumBuckets        256  // require 256 buckets
  346. #define kMaxBuffer        100            // sort at most 100 * 500 = 50000 items
  347.  
  348. typedef long    Buffer[kNumElements];    // we don't want to hammer the memory
  349. manager
  350. typedef Buffer    *BufferPtr;                                    // so we allocate space for 500 longs
  351.  
  352. typedef struct
  353.         {
  354.             BufferPtr        theBuffers[kMaxBuffer]; // hold the items as they are added
  355.             long            numItems;                                                                            // how many (filled) buffers have we
  356. got?
  357.             long            current;                                                                                // where does next item go?
  358.         } Bucket, *BucketPtr;
  359.         
  360.  
  361. static BucketPtr theBuckets[kNumBuckets];    // our buckets...
  362.  
  363.  
  364. // allocate space for the buckets and init
  365. void SetupBuckets(void)
  366. {
  367.     long    i, k;
  368.     
  369.     for (i = 0; i < kNumBuckets; i++)
  370.     {
  371.         theBuckets[i] = (BucketPtr) NewPtr(sizeof(Bucket));
  372.         
  373.         for (k = 0; k < kMaxBuffer; k++) theBuckets[i]->theBuffers[k] = NULL;
  374.         theBuckets[i]->numItems = 0;
  375.         theBuckets[i]->current = 0;
  376.     }
  377. }
  378.  
  379. // We're done, release memory
  380. void ClearBuckets(void)
  381. {
  382.     long    i, k;
  383.     
  384.     for (i = 0; i < kNumBuckets; i++)
  385.     {
  386.         for (k = 0; theBuckets[i]->theBuffers[k] != NULL; k++)
  387.         {
  388.             DisposPtr((Ptr) theBuckets[i]->theBuffers[k]);
  389.         }
  390.         DisposPtr((Ptr) theBuckets[i]);
  391.     }
  392. }
  393.  
  394. // Stuff what we've put into the buffers back into the array and release
  395. mem.
  396. void CopyBuckets(long theArray[])
  397. {
  398.     register long    i, j, k, l, count;
  399.     
  400.     count = 0;
  401.     for (i = 0; i < kNumBuckets; i++)
  402.     {
  403.         for (j = 0; j <= theBuckets[i]->numItems; j++) // number of filled
  404. buffers
  405.         {
  406.             if (j < theBuckets[i]->numItems) l = kNumElements; //full buffer
  407.             else l = theBuckets[i]->current;                                                                            //partially full
  408.             
  409.             for (k = 0; k < l; k++)
  410.             {
  411.                 theArray[count] = (*theBuckets[i]->theBuffers[j])[k];
  412.                 count++;
  413.             }
  414.          if (theBuckets[i]->theBuffers[j])
  415.             {
  416.                 free((void *) theBuckets[i]->theBuffers[j]);
  417.                 theBuckets[i]->theBuffers[j] = NULL;
  418.             }
  419.         }
  420.         theBuckets[i]->numItems = 0;
  421.         theBuckets[i]->current = 0;
  422.     }
  423. }
  424.  
  425.  
  426. void RadixSort(long theArray[], long numItems)
  427. {
  428.     register long    i, k;
  429.     register unsigned char    c;
  430.     short Offset[kNumPasses] = {BYTE0,BYTE1,BYTE2,BYTE3};
  431.      unsigned char *p;
  432.  
  433.     long    mem, waste;
  434.     
  435.     mem = FreeMem();
  436.     
  437.     SetupBuckets();
  438.     
  439.     for (i = 0; i < kNumPasses; i++)
  440.     {
  441.         for (k = 0; k < numItems; k++)
  442.         {
  443.             
  444.              p = (unsigned char *) &theArray[k] + Offset[i];
  445.              c = *p;
  446.             if (!theBuckets[c]->theBuffers[theBuckets[c]->numItems])
  447.             {
  448.                 theBuckets[c]->theBuffers[theBuckets[c]->numItems] = (BufferPtr)
  449. malloc(sizeof(Buffer));
  450.                 theBuckets[c]->current = 0;
  451.             }
  452.             
  453.             (*theBuckets[c]->theBuffers[theBuckets[c]->numItems])[theBuckets[c]->current]
  454. = theArray[k];
  455.             
  456.             theBuckets[c]->current++;
  457.             if (theBuckets[c]->current >= kNumElements)
  458.             {
  459.                 theBuckets[c]->numItems++;
  460.                 theBuckets[c]->current = 0;
  461.             }
  462.         }
  463.         CopyBuckets(theArray);
  464.     }
  465.     ClearBuckets();
  466.     waste = mem - FreeMem();
  467. }
  468.  
  469.  
  470.  
  471. +-----------------------------------------------------------------+
  472. |Chris Reid                            e-mail: cr@cs.strath.ac.uk |
  473. |Dept. Computer Science, Strathclyde University, Glasgow, Scotland|
  474. +-----------------------------------------------------------------+
  475.  
  476. +++++++++++++++++++++++++++
  477.  
  478. >From pcastine@jake.prz.tu-berlin.de (Peter Castine)
  479. Date: Mon, 6 Jun 1994 14:42:31 GMT
  480. Organization: PRZ TU-Berlin
  481.  
  482. cr@cs.strath.ac.uk (Chris Reid) writes:
  483. >
  484. >Hi everybody,
  485. >
  486. >I have written some code that implements Radix Sort (it sorts
  487. >an array of longs in linear time). It seems to work well enough,
  488. >but one thing is really strange: when I replace the NewPtr()
  489. >calls with calls to malloc(), the corresponding free() doesn't seem
  490. >to work. Here's roughly what happens:
  491. >
  492. [stuff deleted]
  493.  
  494. Well, as I remember, malloc() calls _NewPtr, but free() (at least
  495. in the THINK C implementation) does not (necessarily) call _DisposPtr.
  496. The malloc/free implementation does some of its own store management.
  497. So, what you're seeing is not (ahem, necessarily) a memory leak.
  498. Check the sources of malloc() and free() for details.
  499.  
  500. BTW, I've seen some code that checks the endian-ness of the machine
  501. at runtime. This might be a better idea than depending upon MAC
  502. or PC being #defined. The trick is to store an arbitrary value
  503. (like 0x1234) into a short, and looking at the first byte (by 
  504. typecasting the address of the variable to a char*). 
  505. Just a suggestion.
  506.  
  507. Cheers,
  508. -- 
  509. Peter Castine              | Dr. Who quote du jour:
  510. pcastine@prz.tu-berlin.de  |     Have you noticed the way people's
  511. ===========================| intelligence capabilities decline sharply
  512.  ``Have Mac, will travel'' | the minute they start waving guns around?
  513.  
  514. +++++++++++++++++++++++++++
  515.  
  516. >From isis@netcom.com (Mike Cohen)
  517. Date: Mon, 6 Jun 1994 17:05:40 GMT
  518. Organization: ISIS International
  519.  
  520. cr@cs.strath.ac.uk (Chris Reid) writes:
  521.  
  522. <snip>
  523.  
  524. >// RadixSort implemented using malloc() and free()
  525.  
  526. >mem = FreeMem();    // We've got amount 'mem' bytes in the heap
  527. >RadixSort(someArray, numItems);    // Do the sorting
  528. >waste = mem - FreeMem();    // Is there a memory leak?
  529.  
  530. >waste is non-zero, a very disturbing fact. But it gets even better,
  531. >because on consecutive calls, waste IS zero. It looks as if
  532. >malloc() remebers what it's done before. By the way, I need to
  533. >use malloc() because the code has to be (sort of) platform independent.
  534.  
  535. In most implementations of malloc/free, rather than simply calling NewPtr &
  536. DisposePtr directly, they will allocate a larger pool calling NewPtr as
  537. necessary and then manage the space in that pool. In most cases, this pool
  538. storage won't be returned to the mac memory manager, but will remain available
  539. for future malloc() calls. Therefore, FreeMem() will report that storage was
  540. lost.
  541. -- 
  542. Mike Cohen - isis@netcom.com
  543. NewtonMail, eWorld: MikeC / ALink: D6734 / AOL: MikeC20
  544. Home Page: file://ftp.netcom.com/pub/isis/home.html
  545.  
  546. +++++++++++++++++++++++++++
  547.  
  548. >From Jens Alfke <jens_alfke@powertalk.apple.com>
  549. Date: Mon, 6 Jun 1994 21:11:22 GMT
  550. Organization: Apple Computer
  551.  
  552. Chris Reid, cr@cs.strath.ac.uk writes:
  553. > waste is non-zero, a very disturbing fact. But it gets even better,
  554. > because on consecutive calls, waste IS zero. It looks as if
  555. > malloc() remebers what it's done before. By the way, I need to
  556. > use malloc() because the code has to be (sort of) platform independent.
  557.  
  558. This is a very Frequently Asked Question. malloc and free as implemented by
  559. the ANSI library (on all know Mac development systems) grab large blocks of
  560. memory via NewPtr, then suballocate those blocks for successive mallocs.
  561. These large blocks don't get returned -- it would be difficult to figure out
  562. when to return them. But the memory in them does get re-used by malloc if you
  563. free it.
  564.  
  565. Think of it as if malloc and free create a new heap from which to allocate
  566. memory.
  567.  
  568. --Jens Alfke
  569.   jens_alfke@powertalk              Rebel girl, rebel girl,
  570.             .apple.com              Rebel girl you are the queen of my world
  571.  
  572. +++++++++++++++++++++++++++
  573.  
  574. >From hall_j@sat.mot.com (Joseph Hall)
  575. Date: Mon, 6 Jun 1994 18:48:45 GMT
  576. Organization: Motorola Inc., Satellite Communications
  577.  
  578. Seems it was cr@cs.strath.ac.uk (Chris Reid) who said:
  579. >Hi everybody,
  580. >
  581. >I have written some code that implements Radix Sort (it sorts
  582. >an array of longs in linear time). It seems to work well enough,
  583. >but one thing is really strange: when I replace the NewPtr()
  584. >calls with calls to malloc(), the corresponding free() doesn't seem
  585. >to work. Here's roughly what happens:
  586.  
  587. It used to be that THINK C's free() just didn't free blocks.  It
  588. was meant to work that way.  I don't recall whether it didn't free
  589. any blocks or whether it only freed blocks larger than a certain size.
  590.  
  591. MPW's malloc(), on the other hand, was busted around 3.0 or 3.1.
  592. Do some malloc-ing and some free-ing and eventually it would crash.
  593. I don't know whether that was ever fixed, though I reported it.
  594.  
  595. I suggest that you use NewPtr() on the Mac to obtain memory, then
  596. manage it with a memory allocator of your own.  The Aho/Hopcroft/
  597. Ullman algorithms book has a section on allocators, or you could
  598. just make allocations of the desired size with NewPtr().  You can always
  599. obtain a separate zone to work with, too, which makes it easy to
  600. free a whole bunch of stuff en masse.
  601.  
  602. -- 
  603. Joseph Nathan Hall | Joseph's Law of Interface Design: Never give your users
  604. Software Architect | a choice between the easy way and the right way.
  605. Gorca Systems Inc. |                 joseph@joebloe.maple-shade.nj.us (home)
  606. (on assignment)    | (602) 732-2549 (work)  Joseph_Hall-SC052C@email.mot.com
  607.  
  608. +++++++++++++++++++++++++++
  609.  
  610. >From Mark Hanrek <hanrek@cts.com>
  611. Date: Wed, 8 Jun 1994 00:53:17 GMT
  612. Organization: The Information Workshop
  613.  
  614. It seems to me that one should be able to copy the source code for
  615. malloc() and free() into their project, and then determine how to modify
  616. it to actually free the memory that was originally malloc'd.
  617.  
  618. This is what I figure I am going to have to do, because I just discovered
  619. that when I made this routine into a code resource (XCMD) which will run
  620. within HyperCard, it used malloc, and I absolutely must return that
  621. memory, and there is no way I could possibly convert the source code to
  622. using NewPtr without opening a Pandora's Box.  It's just too complex.
  623.  
  624. <sigh>
  625.  
  626. Mark Hanrek
  627.  
  628. +++++++++++++++++++++++++++
  629.  
  630. >From ray@sfu.ca (Ray Davison) (Ray Davison)
  631. Date: Fri, 10 Jun 1994 22:34:46 GMT
  632. Organization: Simon Fraser University
  633.  
  634. In article <Cr1zsu.K4G@crash.cts.com>, Mark Hanrek <hanrek@cts.com> wrote:
  635.  
  636. > It seems to me that one should be able to copy the source code for
  637. > malloc() and free() into their project, and then determine how to modify
  638. > it to actually free the memory that was originally malloc'd.
  639. > This is what I figure I am going to have to do, because I just discovered
  640. > that when I made this routine into a code resource (XCMD) which will run
  641. > within HyperCard, it used malloc, and I absolutely must return that
  642. > memory, and there is no way I could possibly convert the source code to
  643. > using NewPtr without opening a Pandora's Box.  It's just too complex.
  644.  
  645. I once needed to use some Unix code and also didn't want it to use malloc
  646. and free. All I did was include the following in the source:
  647.  
  648. #define free(p) DisposPtr((Ptr)(p))
  649. #define calloc(s,n) ((void *)NewPtrClear(s*n))
  650. #define malloc(s) ((void *)NewPtr(s))
  651.  
  652. Worked fine for me.
  653.  
  654. -- 
  655. Ray Davison
  656. ray@sfu.ca
  657.  
  658. +++++++++++++++++++++++++++
  659.  
  660. >From pcastine@tubprz.prz.tu-berlin.de (Peter Castine)
  661. Date: Sun, 12 Jun 1994 15:28:36 GMT
  662. Organization: PRZ TU-Berlin
  663.  
  664. ray@sfu.ca (Ray Davison) (Ray Davison) writes:
  665. >
  666. >I once needed to use some Unix code and also didn't want it to use malloc
  667. >and free. All I did was include the following in the source:
  668. >
  669. >#define free(p) DisposPtr((Ptr)(p))
  670. >#define calloc(s,n) ((void *)NewPtrClear(s*n))
  671.                                          ~~~~~
  672. >#define malloc(s) ((void *)NewPtr(s))
  673. >
  674. >Worked fine for me.
  675.  
  676. Just on principle, it might be a better idea to put parentheses
  677. around s and n in the macro {to wit: NewPtrClear((s)*(n)) }.
  678. It is, admittedly, a little rare to have complicated expressions 
  679. as parameters to calloc, but 't can happen.
  680.  
  681. Picky me ;-}
  682.  
  683. -- 
  684. Peter Castine              | Dr. Who quote du jour:
  685. pcastine@prz.tu-berlin.de  |     Have you noticed the way people's
  686. ===========================| intelligence capabilities decline sharply
  687.  ``Have Mac, will travel'' | the minute they start waving guns around?
  688.  
  689. ---------------------------
  690.  
  691. >From Jake_V._Bouvrie@bcsmac.org (Jake V. Bouvrie)
  692. Subject: Closing Down the FINDER
  693. Date: Sun,  5 Jun 94 11:52:50 EST
  694. Organization: (none)
  695.  
  696. Is it possible to quit the finder from your app, so that there isn't a finder to
  697. go to ?
  698.  
  699. +++++++++++++++++++++++++++
  700.  
  701. >From mclow@coyote.csusm.edu (Marshall Clow)
  702. Date: 5 Jun 1994 10:33:24 -0700
  703. Organization: California State University San Marcos
  704.  
  705. Jake V. Bouvrie (Jake_V._Bouvrie@bcsmac.org) wrote:
  706. >Is it possible to quit the finder from your app, 
  707. >so that there isn't a finder to go to ?
  708.  
  709. Sure, send it a 'quit' apple event.
  710. Under system 6 it's harder.
  711.  
  712. Marshall Clow
  713. Aladdin Systems
  714. mclow@san_marcos.csusm.edu
  715.  
  716.  
  717. +++++++++++++++++++++++++++
  718.  
  719. >From kenlong@netcom.com (Ken Long)
  720. Date: Sun, 5 Jun 1994 18:19:43 GMT
  721. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  722.  
  723. Do you mean in code or in practice?
  724.  
  725. -Ken-
  726.  
  727. +++++++++++++++++++++++++++
  728.  
  729. >From grobbins@apple.com (Grobbins)
  730. Date: 5 Jun 1994 17:03:01 -0700
  731. Organization: Skunkworks
  732.  
  733. In article <2st294$phj@coyote.csusm.edu>,
  734. Marshall Clow <mclow@coyote.csusm.edu> wrote:
  735. >Jake V. Bouvrie (Jake_V._Bouvrie@bcsmac.org) wrote:
  736. >>Is it possible to quit the finder from your app, 
  737. >>so that there isn't a finder to go to ?
  738. >Sure, send it a 'quit' apple event.
  739.  
  740. Not so fast; there are issues to consider.  Pasted
  741. below is the discussion from the Finder Q&A tech note
  742. (TB 535).
  743.  
  744. Grobbins             grobbins@apple.com
  745.  
  746. Usual disclaimers apply.
  747.  
  748. ______
  749.  
  750.  
  751. from Macintosh Technical Note TB 535 - Finder Q&As:
  752.  
  753. Quitting System 7 Finder
  754. Date Written:  4/17/92
  755. Last reviewed:  6/14/93
  756. I've been thinking of shutting down the System 7 Finder. Is this a cool
  757. thing to do in my application?
  758. ___
  759. We normally recommend that you don't quit the System 7 Finder application.
  760. Nevertheless, there may be a few good reasons to shut down the Finder. For
  761. example, the Installer (the only application Apple ships with a good reason
  762. to do so) sometimes needs to shut down the Finder and all other applications
  763. to make sure system resources aren't being used while they're being updated
  764. by the Installer.
  765.  
  766. If you find yourself in a situation where you need to shut down the Finder,
  767. you should know about a few things:
  768. * Before you shut down the System 7 Finder, use the Process Manager to see
  769. if the File Sharing Extension is running. If so, you should shut it down
  770. before shutting down the Finder. The File Sharing Extension shouldn't be
  771. running without the Finder because the Finder is the only user interface the
  772. File Sharing Extension has. You shouldn't take away the user interface to
  773. file sharing.
  774.  
  775.  There's another good reason to shut down the File Sharing Extension before
  776. the Finder. The Network Extension (not the Network control panel) handles
  777. all the user interface transactions among the Finder, the File Sharing
  778. Monitor control panel, the Sharing Setup control panel, the Users & Groups
  779. control panel, and the File Sharing Extension (the file server). The Network
  780. Extension opens another file, the Users & Groups Data File, so that it can
  781. manipulate users and groups. When you shut down the Finder (with a
  782. kAEQuitApplication Apple event), the Network Extension and its connection to
  783. the Users & Groups Data File are also closed (almost). Because of a minor
  784. bug in the system, the File Manager thinks that the file is closed and that
  785. the FCB used by that access path is free for reuse; however, the File
  786. Sharing Extension thinks the access path to the Users & Groups Data File
  787. from the Network Extension is still open. When the File Manager attempts to
  788. reuse that FCB to open another file later, the file is opened, but because
  789. the File Sharing Extension thinks that FCB is still in use by the Network
  790. Extension, it won't allow access to the file and it returns opWrErr (-49) to
  791. the Open call. At this point, the file that someone was attempting to open
  792. can't be accessed or closed.
  793.  
  794. * If the Finder is shut down and then eventually relaunched, there may be
  795. some fragmentation of the MultiFinder heap. This can occur because the
  796. Finder is the first application to be started, so it's always first in the
  797. MultiFinder heap. When you shut it down, that memory becomes available and
  798. other processes might occupy that space. When the Finder is restarted, if it
  799. can't get into its original space in the MultiFinder heap, it will get
  800. loaded somewhere else and probably won't be shut down again.
  801.  
  802. * In System 7, the Finder is responsible for filling the Apple menu with the
  803. items in the Apple Menu Items folder. When the Finder is gone, so are the
  804. Apple menu items, including things that are important to most users (like
  805. control panels).
  806.  
  807. * If the user has selected background printing with a LaserWriter or
  808. StyleWriter, nothing will print while the Finder is gone. That's because the
  809. Finder is responsible for monitoring the PrintMonitor Documents folder and
  810. launching the PrintMonitor application when necessary.
  811.  
  812.  
  813. +++++++++++++++++++++++++++
  814.  
  815. >From Jake_V._Bouvrie@bcsmac.org (Jake V. Bouvrie)
  816. Date: Sun,  5 Jun 94 21:31:29 EST
  817. Organization: (none)
  818.  
  819. >Do you mean in code or in practice?
  820. Well, i mean in Code, like i call it in my program....
  821.  
  822. +++++++++++++++++++++++++++
  823.  
  824. >From David_B._Lamkins@bmugbost.uu.holonet.net
  825. Date: Wed, 08 Jun 1994 14:29:18 EST
  826. Organization: BMUG Boston
  827.  
  828. Jake_V._Bouvrie@bcsmac.org (Jake V. Bouvrie) wrote:
  829.  
  830. >Is it possible to quit the finder from your app, so that there
  831. >isn't a finder to go to ?
  832.  
  833. Yes.  Assuming you don't mind that it's not a nice thing to do,
  834. you can use Process Manager calls (see IM VI or whatever new
  835. world volume has it) to kill the Finder.  You should also
  836. kill the background process that the File Sharing extension
  837. runs when sharing is turned on - to do otherwise risks
  838. corrupting the Users & Groups file.  This won't get rid of the
  839. Finder forever - it will restart as soon as all other
  840. applications quit.
  841.  
  842. Dave
  843. -BMUG Boston 617-721-5840, East Coast BBS of The World's Largest Mac User Group 
  844.  
  845. +++++++++++++++++++++++++++
  846.  
  847. >From wombat@claris.com (Scott Lindsey)
  848. Date: Wed, 08 Jun 1994 20:14:43 -0800
  849. Organization: Claris Corporation, Vancouver WA
  850.  
  851. In article <2stp3l$kf@apple.com>, grobbins@apple.com (Grobbins) wrote:
  852.  
  853. > In article <2st294$phj@coyote.csusm.edu>,
  854. > Marshall Clow <mclow@coyote.csusm.edu> wrote:
  855. > >Jake V. Bouvrie (Jake_V._Bouvrie@bcsmac.org) wrote:
  856. > >>Is it possible to quit the finder from your app, 
  857. > >>so that there isn't a finder to go to ?
  858. > >Sure, send it a 'quit' apple event.
  859. > Not so fast; there are issues to consider.  Pasted
  860. > below is the discussion from the Finder Q&A tech note
  861. > (TB 535).
  862.  
  863. Not to mention that PowerTalk has certain Finder dependencies.  There's
  864. lots of things that don't work if the Finder isn't running (or even if it
  865. gets relaunched!)  We ran into problems just using Apple's Installer. 
  866. After the Finder restarts, PowerTalk gets in a funny state where it's
  867. basically useless.
  868.  
  869. -- 
  870. Scott Lindsey <wombat@claris.com, wombat@apple.com>
  871. Std. disclaimer: my opinions, not Claris', not Apple's.
  872.  
  873. ---------------------------
  874.  
  875. >From "Andrew C. Plotkin" <ap1i+@andrew.cmu.edu>
  876. Subject: Fat-stripping
  877. Date: Thu,  2 Jun 1994 14:52:31 -0400
  878. Organization: Information Technology Center, Carnegie Mellon, Pittsburgh, PA
  879.  
  880. Which is to say, cutting a fat binary down to a 68K executable, thus
  881. saving space. And the parallel operation of cutting a fat binary down to
  882. a PowerMac executable. 
  883.  
  884. Someone must have written a tiny app to do this. Someone? Anyone? I just
  885. downloaded JPEGview 3.3, which is wonderful, but it looks like I can
  886. save half the disk space it takes up. This situation will continue to
  887. aggravate as fat binaries catch on.
  888.  
  889. (Reassurance: obviously, if I give anyone a copy of a shareware program
  890. which I have fat-stripped, I am obligated to tell them that fact and
  891. point them at an unadulterated version if they want it. Also, some
  892. shareware packages prohibit distributing altered copies at all, and this
  893. would certainly count as alteration. I think a well-behaved fat-stripper
  894. would append "68K" or "PMac" to the executable file name.)
  895.  
  896. If nobody has written this thing, I guess I will. The fat->68K stripper,
  897. anyhow. Unless it's non-trivial (which I guess is the only reason for it
  898. not being written.) Can one just reduce the data fork of the APPL to
  899. zero length, or is it trickier?
  900.  
  901. --Z
  902.  
  903. +++++++++++++++++++++++++++
  904.  
  905. >From tgaul@halcyon.com (Troy Gaul)
  906. Date: Fri, 03 Jun 1994 00:04:49 -0800
  907. Organization: Infinity Systems
  908.  
  909. In article <shvWdjy00gpIIUVOsF@andrew.cmu.edu>, "Andrew C. Plotkin"
  910. <ap1i+@andrew.cmu.edu> wrote:
  911.  
  912. > Which is to say, cutting a fat binary down to a 68K executable, thus
  913. > saving space. And the parallel operation of cutting a fat binary down to
  914. > a PowerMac executable. 
  915. > Someone must have written a tiny app to do this. Someone? Anyone? I just
  916. > downloaded JPEGview 3.3, which is wonderful, but it looks like I can
  917. > save half the disk space it takes up. This situation will continue to
  918. > aggravate as fat binaries catch on.
  919. >  
  920. > (Reassurance: obviously, if I give anyone a copy of a shareware program
  921. > which I have fat-stripped, I am obligated to tell them that fact and
  922. > point them at an unadulterated version if they want it. Also, some
  923. > shareware packages prohibit distributing altered copies at all, and this
  924. > would certainly count as alteration. I think a well-behaved fat-stripper
  925. > would append "68K" or "PMac" to the executable file name.)
  926. > If nobody has written this thing, I guess I will. The fat->68K stripper,
  927. > anyhow. Unless it's non-trivial (which I guess is the only reason for it
  928. > not being written.) Can one just reduce the data fork of the APPL to
  929. > zero length, or is it trickier?
  930.  
  931. I've written such a thing, mostly, anyway.  This type of program is much
  932. more complicated than it may first appear.  
  933.  
  934. The main reason I haven't released/finished mine is that I'm somewhat
  935. worried about the liability if the stripping process damages someone's
  936. application.  And it might be that the stripping will work fine, but if
  937. they try to run it later on the other type of machine, it might do
  938. something bad (rather than just fail to work).  This could be a problem
  939. that would take months, even years to develop, so the original copy might
  940. have been around for easy restoration.
  941.  
  942. Also, stripping 68K code is practically impossible to do safely for various
  943. reasons.
  944.  
  945. _troy gaul
  946.  infinity systems
  947.  
  948. +++++++++++++++++++++++++++
  949.  
  950. >From tgaul@halcyon.com (Troy Gaul)
  951. Date: Sat, 04 Jun 1994 22:14:44 -0700
  952. Organization: Infinity Systems
  953.  
  954. In article <scouten-030694090448@cactus.stu.umn.edu>,
  955. scouten@maroon.tc.umn.edu (Eric Scouten) wrote:
  956.  
  957. > You don't really have that much to worry about. If you're writing to strip
  958. > PowerPC code, you only have to read the 'cfrg' resource, find out where the
  959. > PowerPC code is, and get rid of it. In almost all cases, it will be in the
  960. > data fork -- though it is possible to put it in resources (or a *part* of
  961. > the data fork). Such cases are *very* rare, and unsupported by at least two
  962. > of the three major PowerPC development systems.
  963. > If you strip the PPC code properly, you can still launch the application on
  964. > a PPC machine; it'll just run in emulation mode instead. (Just be sure you
  965. > also remove the 'cfrg' resource!)
  966.  
  967. My program actually parses the 'cfrg' resource, and it is aware of the
  968. types of the blocks, etc. (for instance, when the Code Fragment Manager is
  969. implemented on 68K, it won't remove those).
  970.  
  971. The problem with stripping 68K code is that a PowerPC application might
  972. need some of the code resources if it has only been partially ported, and
  973. this is not described in the 'cfrg' resource or anywhere else.
  974.  
  975. _troy
  976. //////// //////___Troy Gaul_________________________tgaul@halcyon.com__ //
  977.   //    //       Infinity Systems ; Redmond, Washington                //
  978.  //    //  //  "Insert witty quote here."                             //
  979. //    //////________________________________________________________ //
  980.  
  981. +++++++++++++++++++++++++++
  982.  
  983. >From "Andrew C. Plotkin" <ap1i+@andrew.cmu.edu>
  984. Date: Mon,  6 Jun 1994 10:41:25 -0400
  985. Organization: Information Technology Center, Carnegie Mellon, Pittsburgh, PA
  986.  
  987. Thanks to everyone who replied. The generic answer seems to be "get
  988. IM-PPC System Software and look up the 'cfrg' resource," which I will do
  989. as soon as my other fifty-seven projects allow me some spare time.
  990.  
  991. --Z
  992.  
  993. "And Aholibamah bare Jeush, and Jaalam, and Korah: these were the borogoves..."
  994.  
  995. +++++++++++++++++++++++++++
  996.  
  997. >From Ron_Hunsinger@bmug.org (Ron Hunsinger)
  998. Date: Sun, 12 Jun 94 08:55:52 PST
  999. Organization: Berkeley Macintosh Users Group
  1000.  
  1001. scouten@maroon.tc.umn.edu (Eric Scouten) writes:
  1002.  
  1003. >If you strip the 68K code properly, you can of course launch on a PPC
  1004. >machine. If you attempt to launch such an app on a 68K machine, the Finder
  1005. >will give you an error box saying something like "The application could not
  1006. >be launched because an error of type -192 occurred." (-192 is resource not
  1007. >found, probably the 'CODE 1' resource) This is harmless; it just means you
  1008. >won't be able to use the app. (Unless they ever come out with PowerPC
  1009. >emulation on 68K... snicker snicker!)
  1010.  
  1011. Or, you could substitute for the 68k code a tiny 68k program that puts up
  1012. an alert saying "This program will not run on your machine because it has
  1013. been customized for PowerMac execution only."  Then you don't have to 
  1014. explain what "an error of type -192" means.
  1015.  
  1016. -Ron Hunsinger
  1017.  
  1018. ---------------------------
  1019.  
  1020. >From eshieh@volga.EECS.Berkeley.EDU (Eric Shieh)
  1021. Subject: Finder Comments and Finder Info Updating
  1022. Date: 9 Jun 1994 21:48:21 GMT
  1023. Organization: University of California, Berkeley
  1024.  
  1025.  
  1026. Hello all, there are a few minor quirks I'm trying to fix in my program.
  1027. First, how do you get the comments off of a floppy disk???IM VI says
  1028. it doesn't use the Desktop Manager for volumes < 2 megs, so you cant
  1029. use PBDTGetComment...I tried using the Morefiles routine, but it doesn't
  1030. seem to like floppies either...
  1031.  
  1032. Second problem: Is there any way to have the Finder update a file's label?
  1033. On a Powermac, whenever I set the label, then do a GetFInfo, the old label
  1034. is still returned, only when I close and re-open the folder does the label
  1035. get correctly set.  I tried "touching" the folder (usually used for
  1036. updating a file's icons) to no avail. This is annoying cuz my program
  1037. can read the label, but if the user changes it, then immediately give it to
  1038. my program, it'll read the old label still...
  1039.  
  1040. Thanks,
  1041. Eric
  1042. eshieh@cory.berkeley.edu
  1043.  
  1044.  
  1045. +++++++++++++++++++++++++++
  1046.  
  1047. >From leonardr@netcom.com (Leonard Rosenthol)
  1048. Date: Sun, 12 Jun 1994 23:13:14 GMT
  1049. Organization: Aladdin Systems, Inc.
  1050.  
  1051. In article <2t82n5$9g0@agate.berkeley.edu>, eshieh@volga.EECS.Berkeley.EDU
  1052. (Eric Shieh) wrote:
  1053.  
  1054. > Hello all, there are a few minor quirks I'm trying to fix in my program.
  1055. > First, how do you get the comments off of a floppy disk???IM VI says
  1056. > it doesn't use the Desktop Manager for volumes < 2 megs, so you cant
  1057. > use PBDTGetComment...I tried using the Morefiles routine, but it doesn't
  1058. > seem to like floppies either...
  1059.    Correct.  Floppies (volumes < 2 meg) use the old Sys6 style DTDB for
  1060. which there were no API calls for accessing the information.  Your only
  1061. option, if you MUST support it, is to figure out the format of the old
  1062. DTDB files and then read/write them...
  1063.  
  1064.  
  1065. > Second problem: Is there any way to have the Finder update a file's label?
  1066. >
  1067.    Not w/o a bunch of weird trap patches, nope.   
  1068.  
  1069.    The problem is that the Finder keeps certain things in an internal
  1070. "cache" and doesn't go back to disk (or doesn't flush it to disk) that
  1071. often.  There is also no (easy/approved/documented) way to get the Finder
  1072. to flush the cache, or reload the data.   There is an Apple event in the
  1073. new Scriptable Finder that allows you to force an "update" on a file, but
  1074. that doesn't help in all cases.
  1075.  
  1076.  
  1077. Leonard
  1078. - ------------------------------------------------------------------------
  1079. Leonard Rosenthol                      Internet:       leonardr@netcom.com
  1080. Director of Advanced Technology        AppleLink:      MACgician
  1081. Aladdin Systems, Inc.                  GEnie:          MACgician
  1082.  
  1083. ---------------------------
  1084.  
  1085. >From Neil Ticktin <publisher@xplain.com>
  1086. Subject: MacTech's ftp site now available!
  1087. Date: Thu, 9 Jun 1994 05:09:17 GMT
  1088. Organization: MacTech Magazine/Xplain Corp.
  1089.  
  1090. To all,
  1091.  
  1092. By popular demand (mostly from you folks on comp.sys.mac.programmer),
  1093. we've now established our ftp site.  To get to our files, do an anonymous
  1094. ftp to ftp.netcom.com and change directories to /pub/xplain -- there
  1095. you'll see our latest files.
  1096.  
  1097. In this site, we will regularly post the most recent 3 months of source
  1098. code to accompany the articles in the magazine.  That way, you can
  1099. download the info and play with the code as soon as you get the magazine.
  1100.  This brings our Internet support inline with our support on America
  1101. Online, CompuServe and AppleLink.
  1102.  
  1103. Please let us know if you have any suggestions.
  1104.  
  1105. Hope it helps,
  1106.  
  1107. Neil Ticktin
  1108. MacTech Magazine
  1109. - ---------------------------------------------------------------------
  1110.            Neil Ticktin, MacTech Magazine (formerly MacTutor)
  1111. PO Box 250055, Los Angeles, CA 90025 * 310-575-4343 * Fax: 310-575-0925
  1112.  For more info, anonymous ftp to ftp.netcom.com and cd to /pub/xplain
  1113.   custservice@xplain.com * editorial@xplain.com * adsales@xplain.com
  1114. marketing@xplain.com * accounting@xplain.com * pressreleases@xplain.com
  1115.    progchallenge@xplain.com * publisher@xplain.com * info@xplain.com
  1116.  
  1117. ---------------------------
  1118.  
  1119. >From Willie Abrams <willie-abrams@uokhsc.edu>
  1120. Subject: QuickDraw GX Display Devices
  1121. Date: 6 Jun 1994 19:03:50 GMT
  1122. Organization: OU Health Sciences Center
  1123.  
  1124. In working with GX, I was wondering -
  1125.  
  1126. When the graphics system gets loaded, I assume GX walks the 
  1127. list of GDevices known to QuickDraw, and creates viewDevices
  1128. for them...
  1129.  
  1130. Would it be possible to have GX draw to a display that was not
  1131. known to QuickDraw? That is, can GX recognize "GX" only display
  1132. hardware?
  1133.  
  1134. And since GX does allow for the definition and storage of 48 bit
  1135. per pixel data, could GX drive a special display board to help
  1136. drive us past the 8 bit grayscale ceiling. Maybe 16 bit grayscale
  1137. boards? :-)
  1138.  
  1139. This does have an application, really.
  1140.  
  1141. Many people in the medical imaging industry and some of our
  1142. customers (radiologists, etc.) believe that even though we have
  1143. been taught that the human eye can detect no more that 256 shades
  1144. of any given tone, that the ability to see 12 bits to 16 bits of
  1145. data is worthwhile and can make a difference on diagnosis. 
  1146.  
  1147.  
  1148. Willie Abrams                
  1149. Telemedicine Software Guy  Internet:  willie-abrams@uokhsc.edu
  1150. OU Health Sciences Center  AppleLink: Willie
  1151.  
  1152. +++++++++++++++++++++++++++
  1153.  
  1154. >From ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University)
  1155. Date: 8 Jun 94 16:39:22 +1200
  1156. Organization: University of Waikato, Hamilton, New Zealand
  1157.  
  1158. In article <2svrum$dff@romulus.ucs.uoknor.edu>, Willie Abrams <willie-abrams@uokhsc.edu> writes:
  1159. >
  1160. > When the graphics system gets loaded, I assume GX walks the
  1161. > list of GDevices known to QuickDraw, and creates viewDevices
  1162. > for them...
  1163. >
  1164. > Would it be possible to have GX draw to a display that was not
  1165. > known to QuickDraw? That is, can GX recognize "GX" only display
  1166. > hardware?
  1167.  
  1168. GX can draw to offscreen ViewDevices, just like QuickDraw supports offscreen
  1169. GWorlds. They're easy to set up. You can even set up offscreen ViewGroups
  1170. (like the set of all screen devices is a ViewGroup), so you can draw a single
  1171. shape to multiple offscreen ViewDevices with a single GXDrawShape call.
  1172.  
  1173. > And since GX does allow for the definition and storage of 48 bit
  1174. > per pixel data, could GX drive a special display board to help
  1175. > drive us past the 8 bit grayscale ceiling. Maybe 16 bit grayscale
  1176. > boards? :-)
  1177.  
  1178. Unfortunately, last I checked in the (beta) documentation, GX cannot draw
  1179. _to_ a destination that has more than 8 bits per pixel component. I think it
  1180. can only read _from_ such a bitmap.
  1181.  
  1182. In short, you can certainly create and manipulate such a structure yourself,
  1183. no problem. And you can even get GX to display and print it (to within the
  1184. limits of your output hardware) once you've done. But GX will only be of
  1185. limited help with the manipulations.
  1186.  
  1187. Lawrence D'Oliveiro                       fone: +64-7-856-2889
  1188. Info & Tech Services Division              fax: +64-7-838-4066
  1189. University of Waikato            electric mail: ldo@waikato.ac.nz
  1190. Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+12:00
  1191.  
  1192. +++++++++++++++++++++++++++
  1193.  
  1194. >From Cary Clark <crclark@apple.com>
  1195. Date: Wed, 8 Jun 1994 04:42:51 GMT
  1196. Organization: Apple Computer, Inc.
  1197.  
  1198. In article <2svrum$dff@romulus.ucs.uoknor.edu> Willie Abrams,
  1199. willie-abrams@uokhsc.edu writes:
  1200. >Would it be possible to have GX draw to a display that was not
  1201. >known to QuickDraw? That is, can GX recognize "GX" only display
  1202. >hardware?
  1203.  
  1204. Yes. An application can create a device in with the gxScreenViewDevices
  1205. viewGroup (1), and then it will be treated like all other physical
  1206. devices. If nil is passed for the mapping to GXSetViewDeviceMapping, the
  1207. device will be located adjacent to but not overlapping the other physical
  1208. devices.
  1209.  
  1210. >And since GX does allow for the definition and storage of 48 bit
  1211. >per pixel data, could GX drive a special display board to help
  1212. >drive us past the 8 bit grayscale ceiling. Maybe 16 bit grayscale
  1213. >boards? :-)
  1214.  
  1215. Sorry, but GX does not allow for pixel sizes greater than 32 bits. Nor
  1216. does it provide for 16 bits/pixel grayscale. But both of these are fine
  1217. enhancement requests for version 2.0.
  1218.  
  1219. Cary Clark
  1220. Apple Computer, Inc.
  1221.  
  1222. ---------------------------
  1223.  
  1224. >From kaltwasc@ucs.orst.edu (Chris Kaltwasser)
  1225. Subject: SEMI-SUMMARY: Reading JPEGs (with code)
  1226. Date: 8 Jun 1994 03:45:29 GMT
  1227. Organization: Oregon State University, Corvallis
  1228.  
  1229. Hello all,
  1230.     A while ago, I asked for a little help/advice on decompressing
  1231. JPEGs from JFIF files using QuickTime, and I'm very pleased to be able to
  1232. report success.  For the benefit of the Mac programming community, here is
  1233. the product of my efforts:
  1234.  
  1235.     This routine reads a JPEG file into an offscreen GWorld.  It would
  1236. not be too difficult to modify it to use an onscreen port instead.  It
  1237. assumes you've already checked for QuickTime and so forth.  Permission is
  1238. given to use this code for non-commercial purposes.  Use at your own risk.
  1239.  
  1240. - ------------------Cut Here--------------------
  1241.  
  1242. //______________________________________________________________________
  1243. //
  1244. //    Code for reading and writing JFIF files for SSConverter 1.4.1
  1245. //
  1246. //    Copyright (c)1994 by Chris Kaltwasser.  All rights reserved.
  1247. //
  1248. //______________________________________________________________________
  1249.  
  1250.  
  1251.  
  1252. #include <ImageCompression.h>
  1253. #include <FixMath.h>
  1254.  
  1255.  
  1256.  
  1257. #define JFIF_ID_MARKER        0xE0
  1258. #define JFIF_INFO_MARKER    0xC0
  1259.  
  1260.  
  1261.  
  1262. OSErr ReadJPEGFile(FSSpec *spec, GWorldPtr *gw)
  1263. {
  1264.     Rect srcRect;
  1265.     GDHandle gdh;
  1266.     PixMapHandle pix;
  1267.     ImageDescriptionHandle descH;
  1268.     CGrafPtr port;
  1269.     Byte *data = NULL, *s, id[5] = "JFIF";
  1270.     long length, i;
  1271.     short j, refnum, err, width, height;
  1272.  
  1273.     if (*gw)
  1274.         DisposeGWorld(*gw);
  1275.     *gw = NULL;
  1276.  
  1277.     err = FSpOpenDF(spec, fsRdPerm, &refnum);
  1278.     if (!err)
  1279.     {
  1280.         err = GetEOF(refnum, &length);
  1281.         if (!err && length < 170L) err = kReadFailErr;
  1282.         if (!err)
  1283.         {
  1284.             data = (Byte*)NewPtr(length);
  1285.             if (!data) err = memFullErr;
  1286.         }
  1287.         if (!err)
  1288.             err = FSRead(refnum, &length, data);
  1289.         FSClose(refnum);
  1290.     }
  1291.  
  1292.     if (!err)
  1293.     {
  1294.         /* make sure data is JFIF data stream */
  1295.         for (i = 0; i < length; ++i)
  1296.             if (data[i] == 0xFF && data[i+1] == JFIF_ID_MARKER)
  1297.             {
  1298.                 for (s = &data[i+4], j = 0; j < 5; ++s, ++j)
  1299.                     if (*s != id[j])
  1300.                     {
  1301.                         err = kBadJFIFErr;
  1302.                         j = 5;
  1303.                     }
  1304.                 i = length;
  1305.             }
  1306.         if (err) goto abortJPEG;
  1307.  
  1308.         /* read JPEG height and width from JFIF stream */
  1309.         err = kBadJFIFErr;
  1310.         for (i = 0; i < length; ++i)
  1311.             if (data[i] == 0xFF && data[i+1] == JFIF_INFO_MARKER)
  1312.             {
  1313.                 height = data[i+5]*256 + data[i+6];
  1314.                 width = data[i+7]*256 + data[i+8];
  1315.                 err = noErr;
  1316.                 i = length;
  1317.             }
  1318.  
  1319.         if (!err)
  1320.         {
  1321.             srcRect.top = 0;
  1322.             srcRect.left = 0;
  1323.             srcRect.bottom = height;
  1324.             srcRect.right = width;
  1325.  
  1326.             err = NewGWorld(gw, 24, &srcRect, NULL, NULL, 0);
  1327.  
  1328.             GetGWorld(&port, &gdh);
  1329.             SetGWorld(*gw, NULL);
  1330.             ClipRect(&srcRect);
  1331.             ForeColor(blackColor);
  1332.             BackColor(whiteColor);
  1333.  
  1334.             descH = (ImageDescriptionHandle)NewHandle(sizeof(ImageDescription));
  1335.             HLock((Handle)descH);
  1336.             (**descH).idSize = sizeof(ImageDescription);
  1337.             (**descH).cType = 'jpeg';    
  1338.             (**descH).resvd1 = 0L;
  1339.             (**descH).resvd2 = 0;
  1340.             (**descH).dataRefIndex = 0;
  1341.             (**descH).version = 1;
  1342.             (**descH).revisionLevel = 1;
  1343.             (**descH).vendor = 'appl';
  1344.             (**descH).temporalQuality = 0;
  1345.             (**descH).spatialQuality = 0;
  1346.             (**descH).width = width;
  1347.             (**descH).height = height;
  1348.             (**descH).vRes = (**descH).hRes = Long2Fix(72L);
  1349.             (**descH).dataSize = length;
  1350.             (**descH).frameCount = 1;
  1351.             BlockMove("\pPhoto - JPEG", (**descH).name, 32L);
  1352.             (**descH).depth = 24;
  1353.             (**descH).clutID = -1;
  1354.             HUnlock((Handle)descH);
  1355.  
  1356.             pix = GetGWorldPixMap(*gw);
  1357.  
  1358.             if (LockPixels(pix))
  1359.             {
  1360.                 err = DecompressImage((Ptr)data, descH, pix, &srcRect, &srcRect,
  1361.                                     srcCopy, NULL);
  1362.                 UnlockPixels(pix);
  1363.             }
  1364.             else
  1365.                 err = memFullErr;
  1366.  
  1367.             SetGWorld(port, gdh);                    /* restore port and device */
  1368.  
  1369.             DisposeHandle((Handle)descH);
  1370.         }
  1371.     }
  1372.  
  1373. abortJPEG:
  1374.     if (data) DisposePtr((Ptr)data);
  1375.  
  1376.     return err;
  1377. }
  1378.  
  1379. ---------------------------
  1380.  
  1381. >From euajgo@eua.ericsson.se (Joakim Grebeno)
  1382. Subject: VBL interrupt & Stack Sniffer
  1383. Date: 10 Jun 1994 07:53:37 GMT
  1384. Organization: Ellemtel Telecom Systems Labs, Stockholm, Sweden
  1385.  
  1386. I can't, over my dead body, find the information describing how to
  1387. enable/disable the stack sniffer! It is supposed to be done by toggling
  1388. a number of system globals but I can't find the info neither in IM 1-6
  1389. nor in the technotes!
  1390.  
  1391. I have the same problem to find which slot in the exception table the
  1392. VBL interrupt occupies!
  1393.  
  1394. Any experiences?
  1395.  
  1396. Thanks in advance!
  1397. Joakim
  1398.  
  1399. --
  1400. Joakim Grebenoe
  1401.  
  1402.  
  1403. +++++++++++++++++++++++++++
  1404.  
  1405. >From bwade@graphics.cornell.edu (Bretton Wade)
  1406. Date: 10 Jun 1994 12:24:44 GMT
  1407. Organization: Program of Computer Graphics -- Cornell University
  1408.  
  1409. I did this once, there is only one low mem global (try 0x0110?) and it used to
  1410. have the name StackLowPt, but I can't find it in the headers anymore. anyway,
  1411. just write a zero to that location to disable the sniffer. 
  1412.  
  1413. BTW, it seems that the thread manager extension from apple already disables
  1414. the sniffer on a global basis. can anybody substantiate this? Protected mem
  1415. would be a better scheme...
  1416. -- 
  1417. _______________________________________________________________________________
  1418.  
  1419.    Bretton Wade (bw16@cornell.edu)
  1420.  
  1421.    Program of Computer Graphics
  1422.    580 Engineering and Theory Center
  1423.    Cornell University
  1424.    Ithaca, NY 14853
  1425.    Voice: (607) 255-6704
  1426.    Fax:   (607) 255-0806
  1427. _______________________________________________________________________________
  1428.  
  1429. +++++++++++++++++++++++++++
  1430.  
  1431. >From ari@world.std.com (Ari I Halberstadt)
  1432. Date: Fri, 10 Jun 1994 15:51:26 GMT
  1433. Organization: The World Public Access UNIX, Brookline, MA
  1434.  
  1435. In article <2t9661$fds@euas20.eua.ericsson.se>,
  1436. Joakim Grebeno <euajgo@eua.ericsson.se> wrote:
  1437. >I can't, over my dead body, find the information describing how to
  1438. >enable/disable the stack sniffer! It is supposed to be done by toggling
  1439. >a number of system globals but I can't find the info neither in IM 1-6
  1440. >nor in the technotes!
  1441.  
  1442. Set the low-memory global StkLowPt to 0.
  1443. -- 
  1444. Ari Halberstadt                                 ari@world.std.com
  1445. One generation passes away, and another generation comes: but the
  1446. earth abides for ever. -- Ecclesiastes, 1:4.
  1447.  
  1448. +++++++++++++++++++++++++++
  1449.  
  1450. >From ari@world.std.com (Ari I Halberstadt)
  1451. Date: Fri, 10 Jun 1994 15:52:52 GMT
  1452. Organization: The World Public Access UNIX, Brookline, MA
  1453.  
  1454. In article <2t9m2c$e6a@merckx.graphics.cornell.edu>,
  1455. Bretton Wade <bw16@cornell.edu> wrote:
  1456. >BTW, it seems that the thread manager extension from apple already disables
  1457. >the sniffer on a global basis. can anybody substantiate this? Protected mem
  1458. >would be a better scheme...
  1459.  
  1460. The last version of the TM (pre-2.0) that I checked just set StkLowPt to zero.
  1461. -- 
  1462. Ari Halberstadt                                 ari@world.std.com
  1463. One generation passes away, and another generation comes: but the
  1464. earth abides for ever. -- Ecclesiastes, 1:4.
  1465.  
  1466. +++++++++++++++++++++++++++
  1467.  
  1468. >From brad@tazboy.jpl.nasa.gov (Brad Pickering)
  1469. Date: 10 Jun 1994 17:59:29 GMT
  1470. Organization: Jet Propulsion Laboratory, Pasadena, CA
  1471.  
  1472. In article <2t9661$fds@euas20.eua.ericsson.se> euajgo@eua.ericsson.se (Joakim Grebeno) writes:
  1473.  
  1474.    Path: elroy.jpl.nasa.gov!lll-winken.llnl.gov!sol.ctr.columbia.edu!howland.reston.ans.net!EU.net!sunic!sics.se!eua.ericsson.se!eua.ericsson.se!euajgo
  1475.    From: euajgo@eua.ericsson.se (Joakim Grebeno)
  1476.    Newsgroups: comp.sys.mac.programmer
  1477.    Date: 10 Jun 1994 07:53:37 GMT
  1478.    Organization: Ellemtel Telecom Systems Labs, Stockholm, Sweden
  1479.    Lines: 16
  1480.    NNTP-Posting-Host: euas66c13.eua.ericsson.se
  1481.    Keywords: VBL, Stack Sniffer
  1482.  
  1483.    I can't, over my dead body, find the information describing how to
  1484.    enable/disable the stack sniffer! It is supposed to be done by toggling
  1485.    a number of system globals but I can't find the info neither in IM 1-6
  1486.    nor in the technotes!
  1487.  
  1488. Set the low memory global called 'StkLowPt' to 0.
  1489. #include <SysEqu.h>
  1490.  
  1491. *(long *)StkLowPt = 0;
  1492.  
  1493.    I have the same problem to find which slot in the exception table the
  1494.    VBL interrupt occupies!
  1495.  
  1496. I think this depends on which mac you have. On the original macs it
  1497. is handled by the autoint1 vector (0x64), which calls some code that
  1498. dispatches through the second entry of the level 1 dispatch table (Lvl1DT + 0x04).
  1499. Some of this is documented in IM II pg 197.
  1500.  
  1501.  
  1502. Brad Pickering
  1503.  
  1504. +++++++++++++++++++++++++++
  1505.  
  1506. >From cverret@vub.ac.be (Verret Chris)
  1507. Date: 11 Jun 1994 06:56:00 GMT
  1508. Organization: Brussels Free Universities (VUB/ULB), Belgium
  1509.  
  1510. Joakim Grebeno (euajgo@eua.ericsson.se) wrote:
  1511. : I can't, over my dead body, find the information describing how to
  1512. : enable/disable the stack sniffer! It is supposed to be done by toggling
  1513. : a number of system globals but I can't find the info neither in IM 1-6
  1514. : nor in the technotes!
  1515.  
  1516. The following did the trick for me:
  1517.  
  1518.  
  1519.  
  1520. Ptr      stkLowPt : 0x110;
  1521. Ptr      savedStkLowPt;
  1522.  
  1523.  
  1524.  
  1525. savedStkLowPt = stkLowPt;
  1526. stkLowPt = NULL;
  1527.  
  1528.  
  1529.  
  1530. stkLowPt = savedStkLowPt;
  1531.  
  1532. +++++++++++++++++++++++++++
  1533.  
  1534. >From jumplong@aol.com (Jump Long)
  1535. Date: 12 Jun 1994 15:44:01 -0400
  1536. Organization: America Online, Inc. (1-800-827-6364)
  1537.  
  1538. In article <2t9661$fds@euas20.eua.ericsson.se>,
  1539. euajgo@eua.ericsson.se (Joakim Grebeno) writes:
  1540.  
  1541. >I can't, over my dead body, find the information describing how to
  1542. >enable/disable the stack sniffer!
  1543.  
  1544. I put a code snippet on the Developer CD called "Switch Stack" that
  1545. shows how to let interrupt code run on a private stack.  It also
  1546. disables and re-enables the stack sniffer correctly.
  1547.  
  1548. - Jim Luther
  1549.  
  1550.  
  1551. ---------------------------
  1552.  
  1553. >From Patrick.Stadelmann@etudiants.unine.ch
  1554. Subject: Writing dcmd with Think C (Q)
  1555. Date: 8 Jun 94 15:04:44 MET
  1556. Organization: University of Neuchatel
  1557.  
  1558.  Hi !
  1559.  
  1560.  Is it possible to write a dcmd with Think C ? If I include the .0 librairies
  1561.  in my project, I get link errors (like DATA_INIT undefined, or something
  1562.  like that).
  1563.  
  1564.  Is there a Think C port of these librairies available somewhere ?
  1565.  
  1566.  Thanks for your help
  1567.  
  1568.  Patrick
  1569.  
  1570. +++++++++++++++++++++++++++
  1571.  
  1572. >From egurney@vcd.hp.com (Eddy J. Gurney)
  1573. Date: Wed, 8 Jun 1994 17:30:28 GMT
  1574. Organization: Hewlett-Packard VCD
  1575.  
  1576. Patrick.Stadelmann@etudiants.unine.ch wrote:
  1577. > Is it possible to write a dcmd with Think C ? If I include the .0 librairies
  1578. > in my project, I get link errors (like DATA_INIT undefined, or something
  1579. > like that).
  1580.  
  1581. > Is there a Think C port of these librairies available somewhere ?
  1582.  
  1583. Even if you do get your 'dcmd' to build under Think, you'll STILL need
  1584. MPW to run the "BuildDCMD" Tool which Apple kindly supplies only as an
  1585. MPW tool, without any source.
  1586.  
  1587. I was about to try the same thing as you when I realized this "gotcha".
  1588.  
  1589. However, if someone has come up with a method for building dcmd's under
  1590. Think, I would love to hear about it.
  1591.  
  1592. --
  1593. Eddy J. Gurney N8FPW   Hewlett-Packard Company, Vancouver (USA!) Division
  1594. egurney@vcd.hp.com                       #include <standard-disclaimer.h>
  1595. "Failures are divided into two classes-- those who thought and never did,
  1596.       and those who did and never thought."     John Charles Salak
  1597.  
  1598. +++++++++++++++++++++++++++
  1599.  
  1600. >From eascharf@u.washington.edu (Elizabeth Scharf)
  1601. Date: 9 Jun 1994 04:21:53 GMT
  1602. Organization: University of Washington, Seattle
  1603.  
  1604. I managed to get TC 5 to build dcmds by using custom headers.  The main 
  1605. file looked like this:
  1606.  
  1607. void    CommandEntry    (void);
  1608. void    main            (void);
  1609.  
  1610. void main (void) 
  1611. {
  1612.     asm {
  1613.         @valid_A4:
  1614.             dc.w    2
  1615.             dc.w    0
  1616.             lea        @valid_A4,a0
  1617.             bra        CommandEntry
  1618.         } /* asm */
  1619.  
  1620. }
  1621.  
  1622. (remember, for a custom header, put NOTHING else in this file!)
  1623.  
  1624. The main dcmd entrypoint looked like this:
  1625.  
  1626. #include <SetUpA4.h>
  1627. #include "dcmd.h"
  1628.  
  1629. pascal void CommandEntry (
  1630.  
  1631.     dcmdBlock    *paramPtr)
  1632.  
  1633.     { /* begin CommandEntry */
  1634.  
  1635.         RememberA0();
  1636.         SetUpA4();
  1637.         
  1638.         switch (paramPtr->request) {
  1639. ...
  1640.  
  1641.             } /* switch */
  1642.         
  1643.         RestoreA4();
  1644.         
  1645.     } /* end CommandEntry */
  1646.  
  1647. (and you even get globals!)
  1648.  
  1649. I think I used oconv on the dcmdGlue.Lib, but it was a while ago...
  1650.  
  1651. Hope this helps.
  1652.  
  1653. rmgw
  1654.  
  1655. This is not my account:  Please address replies to hawkfish@aol.com
  1656.  
  1657. Disclaimer:  All views expressed are entirely my own and do not reflect 
  1658. the opinions of Elizabeth Scharf or the University of Washington.
  1659.  
  1660. - ---------------------------------------------------------------------------
  1661. Richard Wesley             | A Capitalist is someone who   | "Intel Inside"
  1662. hawkfish@aol.com           | knows the price of everything | is a warning 
  1663. 71062.1711@compuserve.com  | and the value of nothing.     | label...
  1664. - ---------------------------------------------------------------------------
  1665.  
  1666.  
  1667. ---------------------------
  1668.  
  1669. End of C.S.M.P. Digest
  1670. **********************
  1671.  
  1672.  
  1673.