Re: Recursive subroutine for reading null-terminated string



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
.



Relevant Pages

  • dgemm subroutine in BLAS - I think Ive cracked the difference, please confirm
    ... see what I'm talking about), so in the current state of memory allocation, ... but I have a problem when it comes to applying the dimensions. ... > In the Fortran 66 days it was because dynamic allocation didn't exist, ... > you allocate arrays big enough for the largest problem you might run into. ...
    (comp.lang.fortran)
  • Memory allocation on Windows XP
    ... I am working on an app that need a lot of memory. ... This is probably due to the pattern of memory allocation I use. ... Basically the app allocates small chunks and large chunks of memory, ...
    (microsoft.public.win32.programmer.kernel)
  • memory allocation overhead
    ... features of the application is its memory management. ... dynamic memory allocation at this time were slow (inner ... dynamic size arrays at run time. ... The scratch arrays can be easily implemented as automatic arrays. ...
    (comp.lang.fortran)
  • Re: buddy system
    ... A good resource would be nice as well describing the buddy system. ... Memory allocation is done in ... In case there is no free chunks of a specific size, ... a larger allocation can be split in two. ...
    (comp.os.linux.development.system)
  • Re: buddy system
    ... >> memory. ... A good resource would be nice as well describing the buddy system. ... > In case there is no free chunks of a specific size, ... > a larger allocation can be split in two. ...
    (comp.os.linux.development.system)