home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sys / mac / programm / 22009 < prev    next >
Encoding:
Text File  |  1993-01-23  |  2.5 KB  |  64 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!usc!rpi!batcomputer!cornell!rochester!galileo.cc.rochester.edu!uhura.cc.rochester.edu!lhep_ltd
  3. From: lhep_ltd@uhura.cc.rochester.edu (Leonidas Hepis)
  4. Subject: Need (TB) template to write file... fast!
  5. Message-ID: <1993Jan23.051359.21857@galileo.cc.rochester.edu>
  6. Sender: news@galileo.cc.rochester.edu
  7. Nntp-Posting-Host: uhura.cc.rochester.edu
  8. Organization: University of Rochester - Rochester, New York
  9. Date: Sat, 23 Jan 93 05:13:59 GMT
  10. Lines: 52
  11.  
  12. Hello there!
  13.  
  14. I'm a novice in programming the Macintosh.  I'm close to finishing a simple
  15. application and I need to save a file of bytes.  I'm currently using Pascal's
  16. write/read functions to do so: it takes for ever and the resulting file is twice
  17. as big as the original file in the computer.
  18.  
  19. The huge array in the computer's memory is in the form advised in the Pascal
  20. manual (note for the example: ArraySize = 140,000)
  21.  
  22.  type
  23.   MidiByte = byte;
  24.   SysExFile = file of MidiByte; {this type for the in/out files of Pascal r/w}
  25.  
  26.   SysexArrayType = packed array[0..ArraySize] of Midibyte;
  27.   SysexArrayPtr = ^SysexArrayType;
  28.   SysexArrayHandle = ^SysexArrayPtr;
  29.  
  30.  var
  31.   theOldSysExFile, theNewSysExFile: SysExFile; {for the Pascal i/o routines}
  32.   theOldSysExFileName, theNewSysExFileName: string; {for the Pascal i/o }
  33.  
  34.   hSysexArray: SysexArrayHandle;  {the handle to the huge array}
  35.  
  36. Here's the method I use to save the file.  It uses Pascal's read/write.
  37.  
  38.   theNewSysExFileName := newfilename('Name of bulk file to create:');
  39.   if not (theNewSysExFileName = '') then
  40. {if there was a file path returned, i.e. if no Cancel was pressed}
  41.    begin {THIS IS THE BLOCK THAT TAKES A LOT OF TIME}
  42.      rewrite(theNewSysExFile, theNewSysExFileName);
  43.      for writecount := 1 to count - 1 do {'count' has the # of actual bytes}
  44.                                          { in the huge array (plus one)}
  45.        write(theNewSysExFile, hSysexArray^^[writecount]);
  46.      close(theNewSysExFile);
  47.      writeln('File saving completed.');
  48.    end;
  49.  
  50. Is there a novice-proof ;-) method of saving this array onto disk so that it's
  51. done quickly and efficiently (for 140,000 bytes it writes a file 140K not 275K)?
  52. Will the method guard against not enough space on disk so that it doesn't write
  53. over any other files?
  54.  
  55. Thanks.
  56.  
  57. -leo
  58.  
  59. -- 
  60. How can I believe in God when every time I get kicked in |Leonidas Hepis
  61. the pants it hurts ALL THE WAY UP TO THE SPLEEN ?! When  |
  62. that happens to me I see NO Intelligent Divine Designer! |lhep_ltd@uhura
  63. I see chaos and stars and birds flying around my head :) |.cc.rochester.edu
  64.