Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > sci.stat.math > #10924

Re: realloc() - frequency, conditions, or experiences about relocation?

From Ben Bacarisse <ben@bsb.me.uk>
Newsgroups comp.lang.c, sci.stat.math
Subject Re: realloc() - frequency, conditions, or experiences about relocation?
Followup-To comp.lang.c
Date 2024-06-19 22:24 +0100
Organization A noiseless patient Spider
Message-ID <87o77wsk18.fsf@bsb.me.uk> (permalink)
References (5 earlier) <20240617180249.96dfaafa89392827aa162434@g{oogle}mail.com> <v4tuvf$1qto5$1@dont-email.me> <v4u7dm$1t2pu$1@dont-email.me> <875xu5t066.fsf@bsb.me.uk> <v4v58t$230rh$1@dont-email.me>

Cross-posted to 2 groups.

Followups directed to: comp.lang.c

Show all headers | View raw


David Brown <david.brown@hesbynett.no> writes:

> On 19/06/2024 17:36, Ben Bacarisse wrote:
>> Growing the buffer exponentially is simple and effective.
>
> Yes, that's the general way to handle buffers when you don't know what size
> they should be.
>
> A better solutions for this sort of program is usually, as you say, asking
> the OS for the file size (there is no standard library function for getting
> the file size, but it's not hard to do for any realistic target OS).  And
> then for big files, prefer mmap to reading the file into a buffer.
>
> It's only really for unsized "files" such as piped input that you have no
> way of getting the size, and then exponential growth is the way to go.
> Personally, I'd start with a big size (perhaps 10 MB) that is bigger than
> you are likely to need in practice, but small enough that it is negligible
> on even vaguely modern computers. Then the realloc code is unlikely to be
> used (but it can still be there for completeness).

There are other uses that have nothing to do with files.  I have a small
dynamic array library (just a couple of function) that I use for all
sorts of things.  I can read a file or parse tokens or input a line just
by adding characters.  Because of its rather general use, I don't start
with a large buffer (though the initial size can be set).

-- 
Ben.

Back to sci.stat.math | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Re: realloc() - frequency, conditions, or experiences about relocation? Anton Shepelev <anton.txt@g{oogle}mail.com> - 2024-06-17 18:02 +0300
  Re: realloc() - frequency, conditions, or experiences about relocation? "David Jones" <dajhawk18xx@@nowhere.com> - 2024-06-18 17:59 +0000
  Re: realloc() - frequency, conditions, or experiences about relocation? davidd02@tpg.com.au (David Duffy) - 2024-06-19 06:48 +0000
    Re: realloc() - frequency, conditions, or experiences about relocation? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2024-06-19 10:12 +0100
      Re: realloc() - frequency, conditions, or experiences about relocation? Ben Bacarisse <ben@bsb.me.uk> - 2024-06-19 16:36 +0100
        Re: realloc() - frequency, conditions, or experiences about relocation? David Brown <david.brown@hesbynett.no> - 2024-06-19 19:41 +0200
          Re: realloc() - frequency, conditions, or experiences about relocation? Ben Bacarisse <ben@bsb.me.uk> - 2024-06-19 22:24 +0100
      Re: realloc() - frequency, conditions, or experiences about relocation? Anton Shepelev <anton.txt@gmail.moc> - 2024-06-20 01:53 +0300
        Re: realloc() - frequency, conditions, or experiences about relocation? Anton Shepelev <anton.txt@g{oogle}mail.com> - 2024-07-08 19:34 +0300
    Re: realloc() - frequency, conditions, or experiences about relocation? Anton Shepelev <anton.txt@g{oogle}mail.com> - 2024-06-19 15:20 +0300
  Re: realloc() - frequency, conditions, or experiences about relocation? Rich Ulrich <rich.ulrich@comcast.net> - 2024-07-02 00:51 -0400
    Re: realloc() - frequency, conditions, or experiences about relocation? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-07-01 22:10 -0700
      Re: realloc() - frequency, conditions, or experiences about relocation? Rich Ulrich <rich.ulrich@comcast.net> - 2024-07-02 11:45 -0400
        Re: realloc() - frequency, conditions, or experiences about relocation? Anton Shepelev <anton.txt@g{oogle}mail.com> - 2024-07-08 20:01 +0300
          Re: realloc() - frequency, conditions, or experiences about relocation? Rich Ulrich <rich.ulrich@comcast.net> - 2024-07-21 19:40 -0400
            Re: realloc() - frequency, conditions, or experiences about relocation? Anton Shepelev <anton.txt@g{oogle}mail.com> - 2024-07-23 16:47 +0300
    Re: realloc() - frequency, conditions, or experiences about relocation? Paul <nospam@needed.invalid> - 2024-07-02 03:02 -0400
      Re: realloc() - frequency, conditions, or experiences about relocation? Rich Ulrich <rich.ulrich@comcast.net> - 2024-07-02 11:52 -0400
        Re: realloc() - frequency, conditions, or experiences about relocation? Rich Ulrich <rich.ulrich@comcast.net> - 2024-07-02 11:58 -0400
          Re: realloc() - frequency, conditions, or experiences about relocation? Paul <nospam@needed.invalid> - 2024-07-02 15:09 -0400
            Re: realloc() - frequency, conditions, or experiences about relocation? James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-07-02 16:54 -0400
            Re: realloc() - frequency, conditions, or experiences about relocation? James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-07-02 16:58 -0400

csiph-web