Bartc said:
news:569670a8-4f4d-4101-ab7c-bcc50625ad94@l64g2000hse.googlegroups.com...
I thought it was some sort of unwritten rule here that when posting
code solutions you tend not to import large elements of your own
library. Otherwise everyone would post their own different version of
getline() and so on.
As it is, everyone does post different versions of code for the same
task (as this thread itself has brilliantly illustrated), so as long as
the post contains all the code to compile into a working program in a
self-sufficient manner, I don't see any harm in including something
from a personal library.
And pete has pre-written functions to read files into linked-lists. He
often posts a link to his website containing this and other C code
occasionally here in clc.
And also there's the possibility, as seems to have happened here, of
using something inappropriate just because it's there. There's no
reason at all to use a linked list to read all the input into memory
(and risking out-of-memory or thrashing for large input).
Well reading a file into a linked-list isn't exactly inappropriate, but
it may be overkill for the small fragment that the OP posted. But it
could be that the OP's actual file contains hundreds or thousands of
email addresses. Constructing a linked-list will obviously take more
storage than a plain linear array, but it makes some tasks like sorting
lines, inserting lines, deleting lines, etc., much more easier. I
suspect that this is the reason why pete uses them.
(Although I suspect pete may have created this over-the-top solution
on purpose..)
Hmm.
Which is more concrete, this code which has a memory requirement of N
or code using fixed memory?
Either code could run out memory on a sufficiently memory starved
system. Besides the linked-list approach has other advantages (which
may not be very pertinent to the particular task the OP wanted) which
must be considered in a fair comparison.