home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11452 < prev    next >
Encoding:
Text File  |  1992-07-22  |  1.3 KB  |  46 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!paladin.american.edu!darwin.sura.net!wupost!monsanto.com!skws02!bcschu
  3. From: bcschu@skws02.monsanto.com (Brett Schultz)
  4. Subject: reading in a matrix from a file
  5. Message-ID: <1992Jul22.213617.18402@tin.monsanto.com>
  6. Sender: news@tin.monsanto.com (USENET News System)
  7. Organization: Monsanto Company
  8. Date: Wed, 22 Jul 1992 21:36:17 GMT
  9. Lines: 35
  10.  
  11. What is the fastest way to allocate space for and read in a matrix from a file?
  12.  
  13. e.g.
  14.  
  15. For a 2X3 matrix the file looks like:
  16. 1
  17. 2
  18. 3 - end of first row
  19. 4
  20. 5
  21. 6 - end of second row
  22.  
  23. The way i was doing it was to first allocate space for the int ** (in this case
  24. 2 of them)
  25.  
  26. then allocate space for the 3 int * as I read through the file.
  27. I'm sure there is a faster way to do this.
  28.  
  29. Note: I have total control of how the file is set up.
  30.  
  31.  
  32. I was wondering if anyone has any ideas on how to allocate space for the matrix
  33. using the least possible number of malloc calls (normally the matrix I am 
  34. reading in is a 20,000X30 matrix so I want to save the number of malloc calls)
  35. and could you use fread or something like that to read in the matrix at one
  36. time and store it in memory.  Remember I can make the file look anyway I want
  37. to make the storage of the matrix the fastest as possible.
  38.  
  39. Thanks,
  40.  
  41. Brett Schultz
  42. email: bcschu@tin.monsanto.com
  43.  
  44.  
  45.  
  46.