Jamie wrote:[color=blue]
> Hello Newsgroup:
>
> I'm not a C programmer, though I've dabbled on and off through the years. (wish
> I could justify doing more in C/C++ because it is enjoyable, just highly time
> consuming compared to other languages)
>
> Mostly when I use 'C' it's just to fork a process set-ID or send a signal to
> another process, etc... real basic stuff. I'm not seasoned in it and still
> find the syntax of structs and arrays confusing.
>
> Anyhow, I was surprised my books don't discuss the area of basic, mundane
> string/append buffers.
>
> Classic example being something that accumulates text (like an expat
> handler in perl might need to do)
>
> I wrote a linked list / string buffer as a pet project, mainly because
> I would like to get better at C, in case I ever have the opportunity
> to use C.
>
> It's linked list is in "blocks", tracks the TAIL of the list rather then the
> head to make appends faster, and it doesn't need to call strlen() on the whole
> string each time an append is required (it only needs strlen() to get the length
> of the new part)
>
> For review/manglement/flames and entanglements:
>
>
http://geniegate.com/other/slbuf/
>
> These compile on a UNIX machine. Using the 'time' command, under *ideal*
> conditions, (larger strings with many many appends and a decent sized block
> size) a combination linked list with a stringbuffer APPEARS to run about 10
> times faster than realloc + strcat. (but, in less then ideal conditions, it can
> end up running slower, low block sizes really slow it down)
>
> The "sample program" is a utility that slurps stdin into a stringbuffer translating
> [<>&"] into their respective HTML entities and spits out a crude HTML document
> of the text. Not exactly a useful program (would of course be best to spit it
> out in chunks) but it does illustrate using the stringbuffer in a "real" program.
> (don't run it on a HUGE file, it slurps all of stdin)
>
> On an old box, 100,000 iterations of 50+ appends takes about 2-3 seconds -vs-
> around 13 seconds for the realloc + strcat approach.
>
> I'm surprised my books don't talk about stringbuffers (Or, perhaps
> I wasn't looking in the right places?) Seems like a really common operation.
>
> Am I missing something obvious?
>
> In practice, are linked lists better at dealing with memory fragmentation,
> or is realloc best? (how do you know when there is fragmentation?)[/color]
I would start by reading the thread "Critic of the Given Code", started
yesterday. People in the know are always going back and forth about
realloc around here. frank