Re: How to take in a string of any size?
From: Jarno A Wuolijoki (jwuolijo_at_cs.Helsinki.FI)
Date: 08/24/04
- Next message: Jürgen Exner: "Re: [OT] Perl to C Converter?"
- Previous message: David Turrell: "gcc's nutty Nethack object code"
- In reply to: josh: "Re: How to take in a string of any size?"
- Next in thread: josh: "Re: How to take in a string of any size?"
- Reply: josh: "Re: How to take in a string of any size?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 24 Aug 2004 02:39:45 +0300
On Mon, 23 Aug 2004, josh wrote:
> SM Ryan wrote:
>
> > # Notice that each time you allocated memory you ask for twice the
> > # amount of memory that you have already used. The only real
> > # benefit that I can see to repeated realloc calls is if the goal
> >
> > There's a minor benefit of that it makes the algorithm O(n) instead
> > of O(n^2).
>
> makes it O(n log n) instead of O(n^2)
>
> Counting and seeking back to the start would be O(n) (even if seeking itself
> is O(n)), as would using some sort of linked structure to store the string.
I haven't followed this thread from the start but is it by any
chance about reallocing in the pattern 1, 2, 4, 8 etc?
If so, at the end you have performed log N calls to realloc
which, if their execution time is linear to the amount of bytes
allocated, consume k*(1+2+4+8+...+2^ceil(log(N))) < 4*k*N time.
- Next message: Jürgen Exner: "Re: [OT] Perl to C Converter?"
- Previous message: David Turrell: "gcc's nutty Nethack object code"
- In reply to: josh: "Re: How to take in a string of any size?"
- Next in thread: josh: "Re: How to take in a string of any size?"
- Reply: josh: "Re: How to take in a string of any size?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|