Re: Variable-sized lines of text in linked list



Richard Heathfield wrote:
CBFalconer said:
Scottman wrote:

I am trying to read a text file into memory without any knowledge
of how long each line will be. I am looking to store each line
in a linked list structure, however, I am unsure of how to
dynamically allocate space for each line.

Just get the (short and simple) function ggets(), in ggets.zip.

...and be aware of its problems. Chuck, if you're going to keep on
pimping this function, shouldn't you at least warn people of its
shortcomings?

I don't consider them shortcomings. They are that, since the
routine can collect lines of ANY length, that if you can supply a
sufficiently long line without any line terminations (normally
meaning <return> chars typed) the routine will malloc sufficient
space. If you then fail to free that space (normally a memory leak
error) it won't be freed, and you can run out of memory. Unlikely
in practice, and requires careful programmer and user
concentration.

Similarly all users of malloc, calloc, or realloc should be warned
that repeated use or use for sufficiently large demands can run out
of memory.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.



--
Posted via a free Usenet account from http://www.teranews.com

.



Relevant Pages

  • Re: IOCP touching my OVERLAPPED after my Write has completed
    ... Your code will leak memory in this case. ... WSASendTo() it seems a bit different. ... uncommitted by the completion routine. ... FreeRequest(req); //in debug I decommit the memory of this request ...
    (microsoft.public.win32.programmer.kernel)
  • Re: [PATCH] x86_64/__iowrite32_copy: dont use string move for PIO writes
    ... is little point in writing this in assembly at all. ... does the I/O operations 32 bits at a time, ... The point of the routine is to make sure that transfers are *at least* ... which you better not if you're accessing WC memory. ...
    (Linux-Kernel)
  • Re: Handling SSC interrupts in Applesoft BASIC
    ... The Apple 2 has what is called "memory mapped I/O". ... One way is to POKE values into selected ZERO PAGE locations. ... Where to put the routine? ... You could assemble it by hand! ...
    (comp.sys.apple2.programmer)
  • Memory Resource Management
    ... how long a particular routine takes to execute from the static library. ... do this I am using gettimeofdayto calculate the elapsed time. ... OpenOffice and FireFox to sort of reset the scheduler and memory resource ... allocations occur again but the OS's memory manager just reuses the same ...
    (comp.os.linux.development.apps)
  • Re: Efficient memory truncation of a matrix
    ... The whole point of this mex routine is to modify an array in place since you haven't got the memory to make a copy. ... mwSize j, M, N, Mnew, sadd, tadd; ... int i, ElementSize; ...
    (comp.soft-sys.matlab)