Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.postscript > #1141
| From | John Deubert <john@acumentraining.com> |
|---|---|
| Organization | Acumen Training |
| Newsgroups | comp.lang.postscript |
| Date | 2012-12-04 07:03 -0800 |
| Message-ID | <2012120407031929493-john@acumentrainingcom> (permalink) |
| References | <87624kp6hc.fsf@Compaq.site.inet> <y7Pus.223533$kt5.184865@fx08.am4> <2012120313202243338-john@acumentrainingcom> <o5jvs.446497$Wc4.79492@fx10.am4> |
| Subject | Re: Putting lines from a file into an array |
On 2012-12-04 09:09:40 +0000, Chris said: > On Mon, 03 Dec 2012 13:20:22 -0800, John Deubert wrote: > > <SNIP> >> As I say, not as simple as Chris' version, but it does work around the >> stack limitation. I'd go with Chris' code unless the number of lines was >> likely to be northward of 1000 lines or so. (By the way, there's some >> cleanup one could do on this code, but lunch is beckoning.) > > FWIW, that wasn't "my version": I tried to answer the question by making > minimal changes to the OP's code. > > If I were writing it from scratch myself, I would either (assuming we > know we'd always have a positionable file stream, or that we're allowed > to use ReusableStreamDecode) not read in the entire file at all, but just > find and keep the line(s) of interest at a given time. > > *Or* I would use (sort of) half of your solution, and use a dictionary as > the "permanent" storage for the file contents, with the line numbers as > the keys. In addition, I would have a single, large line buffer which > gets reused for reading from the file, then I would get the actual length > of each line, and copy it to a new, correctly sized string. Thus > minimising redundant memory use. > > Creating and copying the strings and writing to the dictionary would be > appreciably slower, *but* the bottleneck will always be reading from the > file. And on a decent interpreter, there shouldn't be an appreciable > difference in performance between iterating through a dictionary vs an > array. > > I feel both those would scale better than using an array. > > Chris No offense intended. I assumed you knew about the stackoverflow problem and were presenting a minimum-change solution. I called it "Chris' solution" because, um, well, I had to call it *something.* - J -- ======== John Deubert Acumen Training PostScript & PDF Engineering Classes & Consulting www.acumentraining.com Learn PostScript programming techniques Read the free Acumen Journal acumentraining.com/acumenjournal.html
Back to comp.lang.postscript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Putting lines from a file into an array Cecil Westerhof <Cecil@decebal.nl> - 2012-12-02 21:02 +0100
Re: Putting lines from a file into an array Chris <cjl@spamcop.net> - 2012-12-02 20:47 +0000
Re: Putting lines from a file into an array Cecil Westerhof <Cecil@decebal.nl> - 2012-12-03 00:52 +0100
Re: Putting lines from a file into an array Don Lancaster <don@tinaja.com> - 2012-12-05 11:58 -0700
Re: Putting lines from a file into an array "luser.droog" <luser.droog@gmail.com> - 2012-12-05 23:19 -0600
Re: Putting lines from a file into an array John Deubert <john@acumentraining.com> - 2012-12-03 13:20 -0800
Re: Putting lines from a file into an array "luser.droog" <luser.droog@gmail.com> - 2012-12-04 00:58 -0600
Re: Putting lines from a file into an array Chris <cjl@spamcop.net> - 2012-12-04 09:09 +0000
Re: Putting lines from a file into an array John Deubert <john@acumentraining.com> - 2012-12-04 07:03 -0800
Re: Putting lines from a file into an array Chris <cjl@spamcop.net> - 2012-12-04 17:46 +0000
Re: Putting lines from a file into an array Cecil Westerhof <Cecil@decebal.nl> - 2012-12-04 17:17 +0100
Re: Putting lines from a file into an array "luser.droog" <luser.droog@gmail.com> - 2012-12-02 15:31 -0600
Re: Putting lines from a file into an array Cecil Westerhof <Cecil@decebal.nl> - 2012-12-03 02:19 +0100
Re: Putting lines from a file into an array "luser.droog" <luser.droog@gmail.com> - 2012-12-02 23:28 -0600
Re: Putting lines from a file into an array Cecil Westerhof <Cecil@decebal.nl> - 2012-12-03 10:01 +0100
Re: Putting lines from a file into an array luser droog <luser.droog@gmail.com> - 2016-08-01 13:25 -0700
Re: Putting lines from a file into an array JohnF <john@please.see.sig.for.email.com> - 2016-08-02 03:39 +0000
Re: Putting lines from a file into an array luser droog <luser.droog@gmail.com> - 2016-08-02 21:58 -0700
Re: Putting lines from a file into an array Tonton Th <tTh@nowhere.invalid> - 2016-08-03 05:10 +0000
Re: Putting lines from a file into an array luser droog <luser.droog@gmail.com> - 2016-08-02 22:20 -0700
Re: Putting lines from a file into an array luser droog <luser.droog@gmail.com> - 2016-08-02 22:35 -0700
Re: Putting lines from a file into an array JohnF <john@please.see.sig.for.email.com> - 2016-08-03 06:21 +0000
Re: Putting lines from a file into an array JohnF <john@please.see.sig.for.email.com> - 2016-08-03 06:32 +0000
Re: Putting lines from a file into an array luser droog <luser.droog@gmail.com> - 2016-08-22 22:31 -0700
csiph-web