home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18818 < prev    next >
Encoding:
Internet Message Format  |  1993-01-07  |  1.7 KB

  1. Path: sparky!uunet!spool.mu.edu!sgiblab!adagio.panasonic.com!nntp-server.caltech.edu!willow!roy
  2. From: Roy_Williams
  3. Newsgroups: comp.lang.c++
  4. Subject: parsing
  5. Date: 8 Jan 1993 00:34:23 GMT
  6. Organization: CCSF Caltech, Pasadena, CA
  7. Lines: 43
  8. Distribution: world
  9. Message-ID: <1iii6fINNfur@gap.caltech.edu>
  10. Reply-To: roy@willow.ccsf.caltech.edu
  11. NNTP-Posting-Host: willow.ccsf.caltech.edu
  12.  
  13. Suppose I have some class, for example vectors, with lots of
  14. operators defined so I can do things like
  15.  
  16.     a += b + 3*c + a*b;
  17.  
  18. meaning in normal language
  19.  
  20.     for(int i=0; i<vector_length; i++)
  21.         a[i] += b[i] + 3*c[i] + a[i]*b[i];
  22.  
  23. If the vectors are small and 'new' is cheap, we can define
  24. each operator by creating a new one to hold the result, 
  25. evaluating, then returning the whole vector. They get destroyed
  26. by the system.
  27.  
  28. When the vectors get a bit larger, we want to return a pointer
  29. to the new vector, using the magic of reference counting
  30. to do the garbage collection.
  31.  
  32. Now suppose we get stingy about either the time taken for
  33. memory allocation, or we are working at the limits of the
  34. machine's available memory: if I were computing the above
  35. operation with a hand-held calculator and pencil, I wouldn't
  36. write down any temporaries, so I want my implementation of
  37. vectors to do as well.
  38.  
  39. I'd like a vector to be either a set of numbers, as before,
  40. or an operator type and pointer(s) to vector(s). Nothing would 
  41. actually get computed until we get to the assignment (or even
  42. until the thing is written out!).
  43.  
  44. Is there any code or book or reference or ftpable class library 
  45. so I don't have to do this myself? How about optimizing the 
  46. parse tree before evaluation so a*b + a*c becomes a*(b + c)?
  47.  
  48. Roy Williams
  49. Caltech Concurrent Supercomputing Facilities
  50. Pasadena, CA
  51.  
  52.  
  53.  
  54.  
  55.  
  56.