Re: Recursive subroutine for reading null-terminated string
- From: vc4@xxxxxxxxxx
- Date: Tue, 25 Nov 2008 11:41:05 -0800 (PST)
Dear Richard and Gary,
Thanks for your replies!
2. High overhead. You mention that this allocates twice as much memory
as needed. I'd guess that to be a severe underestimate. You appear to be
ignoring the memory involved in the recursive call.
Yes I didn't think/know about this.
Another approach is to gradually increase the size by realocating on the
fly as you read.
I was (wrongly) thinking that this approach is essentially the same
thing as my recursive procedure, but my solution is more elegant/
compact. Of course I did not take into account the overhead.
Another approach to the whole thing is to build a linked list
I have assumed that linked list is a very inefficient way of storing
large arrays. I thought that normal arrays are allocated a single
memory chunk, whereas a linked list is a collection of single
character units with pointers linking each element to the next one.
Hence there is no direct access to elements in the middle, and
everything becomes slow. Am I wrong here? I suppose if the linked list
contains large chunks of data rather than single characters, this will
not be a problem.
Is memory allocation in general a serious problem in terms of speed/
overhead? For instance, is repeated reading of chunks of data into a
pre-allocated array significantly better than allocating the exact
size to the array every time the data are read, and deallocating
afterwards?
Thanks,
Victor
.
- Follow-Ups:
- Re: Recursive subroutine for reading null-terminated string
- From: Richard Maine
- Re: Recursive subroutine for reading null-terminated string
- From: Glen Herrmannsfeldt
- Re: Recursive subroutine for reading null-terminated string
- References:
- Recursive subroutine for reading null-terminated string
- From: vc4
- Re: Recursive subroutine for reading null-terminated string
- From: Richard Maine
- Recursive subroutine for reading null-terminated string
- Prev by Date: Re: How to save, change the (whole) path in fortran (g95) windows
- Next by Date: Re: Pros and cons of assumed-shape arrays
- Previous by thread: Re: Recursive subroutine for reading null-terminated string
- Next by thread: Re: Recursive subroutine for reading null-terminated string
- Index(es):
Relevant Pages
|