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

Liste des GroupesRevenir à cl c 
Sujet : Re: realloc() - frequency, conditions, or experiences about relocation?
De : dajhawk18xx (at) *nospam* (at) *nospam* nowhere.com (David Jones)
Groupes : comp.lang.c sci.stat.math
Date : 18. Jun 2024, 19:59:30
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v4shu2$1ff4q$1@dont-email.me>
References : 1 2 3 4 5 6
User-Agent : XanaNews/1.21-f3fb89f (x86; Portable ISpell)
Anton Shepelev wrote:

[cross-posted to: ci.stat.math]
 
Malcolm McLean:
 
We have a continuously growing buffer, and we want the
best strategy for reallocations as the stream of
characters comes at us. So, given we now how many
characters have arrived, can we predict how many will
arrive,
 
Do you mean in the next bunch, or in total (till the end of
the buffer's lifetime)?
 
and therefore ask for the best amount when we reallocate,
so that we neither make too many reallocation (reallocate
on every byte received) or ask for too much (demand
SIZE_MAX memory when the first byte is received).?
 
Your strategy for avoiding these extremes is exponential
growth. You allocate a small amount for the first few
bytes. Then you use exponential growth, with a factor of
ether 2 or 1.5.
 
This strategy ensures a constant ratio between the amount of
reallocated data to the length of the buffer by making
reallocations less frequent as the buffer grows.
 
And so we integrate the distribution between the point we
are at and infinity. Then we tkae the mean. And that gives
us a best estimate of how many bytes are to come, and
therefore how much to grow the buffer by.
 
You have an apriori distribution of the buffer size (can be
tracked on-the-fly, if unknown beforehand) and a partially
filled buffer.  The task is to calculate the a-posteriori
distribution of that buffer's final size, and then to
allocate the predicted value based on a good percentile.
 
How about using a percentile instead of the mean, e.g. if
the current size corresponds to percentile p, you allocate a
capacity corresponding to percentile 1-(1-p)/k , where k>1
denotes the balance between space and time efficency.  For
example, if the 60th percentile of the buffer is required
and k=2, you allocate a capacity sufficient to hold
100-(100-60)/2=80% of buffers.

Based on essentially no background to this question, not much can be
said. However, if one starts from the suggestion above to use the mean
of some distribution (or later some percentile), one notes that the
"mean" is just the minimum of a quadratic cast function ,,, so an
improvement would be to base the choice on some more realistic cost
function, chosen for the actual application. Given that the scenario
apparently involves a sequence of such decisions, the obvious extension
of the cost-based approach would be to employ some form of dynamic
programming. Of course, this might not be appealing, in which case one
might choose the theoretically-simple approach of tuning a policy based
on good stchastic simulations of the situation.

Date Sujet#  Auteur
17 Jun 24 * realloc() - frequency, conditions, or experiences about relocation?95Janis Papanagnou
17 Jun 24 +- Re: realloc() - frequency, conditions, or experiences about relocation?1Chris M. Thomasson
17 Jun 24 +* Re: realloc() - frequency, conditions, or experiences about relocation?53Ben Bacarisse
17 Jun 24 i`* Re: realloc() - frequency, conditions, or experiences about relocation?52Malcolm McLean
17 Jun 24 i +* Re: realloc() - frequency, conditions, or experiences about relocation?50Ben Bacarisse
17 Jun 24 i i`* Re: realloc() - frequency, conditions, or experiences about relocation?49Malcolm McLean
17 Jun 24 i i +* Re: realloc() - frequency, conditions, or experiences about relocation?21Ben Bacarisse
17 Jun 24 i i i+* Re: realloc() - frequency, conditions, or experiences about relocation?17Anton Shepelev
18 Jun 24 i i ii`* Re: realloc() - frequency, conditions, or experiences about relocation?16Tim Rentsch
18 Jun 24 i i ii +* Re: realloc() - frequency, conditions, or experiences about relocation?8Malcolm McLean
18 Jun 24 i i ii i+* Re: realloc() - frequency, conditions, or experiences about relocation?5Malcolm McLean
29 Jun 24 i i ii ii`* Re: realloc() - frequency, conditions, or experiences about relocation?4Lawrence D'Oliveiro
2 Jul 24 i i ii ii `* Re: realloc() - frequency, conditions, or experiences about relocation?3Malcolm McLean
2 Jul 24 i i ii ii  +- Re: realloc() - frequency, conditions, or experiences about relocation?1Ben Bacarisse
4 Jul 24 i i ii ii  `- Re: realloc() - frequency, conditions, or experiences about relocation?1Lawrence D'Oliveiro
24 Jun 24 i i ii i`* Re: realloc() - frequency, conditions, or experiences about relocation?2Tim Rentsch
24 Jun 24 i i ii i `- Re: realloc() - frequency, conditions, or experiences about relocation?1David Brown
20 Jun 24 i i ii `* Indefinite pronouns [was:Re: realloc() - frequency, conditions, or experiences about relocation?]7Anton Shepelev
20 Jun 24 i i ii  +* Re: Indefinite pronouns3vallor
21 Jun 24 i i ii  i`* Re: Indefinite pronouns2David Brown
21 Jun 24 i i ii  i `- Re: Indefinite pronouns1Keith Thompson
20 Jun 24 i i ii  +* Re: Indefinite pronouns [was:Re: realloc() - frequency, conditions, or experiences about relocation?]2Kenny McCormack
20 Jun 24 i i ii  i`- Re: Indefinite pronouns [was: Re: <something technical>]1Janis Papanagnou
21 Jun 24 i i ii  `- Re: Indefinite pronouns [was:Re: realloc() - frequency, conditions, or experiences about relocation?]1Tim Rentsch
17 Jun 24 i i i+* Re: realloc() - frequency, conditions, or experiences about relocation?2Richard Harnden
17 Jun 24 i i ii`- Re: realloc() - frequency, conditions, or experiences about relocation?1Chris M. Thomasson
17 Jun 24 i i i`- Re: realloc() - frequency, conditions, or experiences about relocation?1Malcolm McLean
17 Jun 24 i i +* Re: realloc() - frequency, conditions, or experiences about relocation?23Anton Shepelev
18 Jun 24 i i i+- Re: realloc() - frequency, conditions, or experiences about relocation?1David Jones
19 Jun 24 i i i+* Re: realloc() - frequency, conditions, or experiences about relocation?9David Duffy
19 Jun 24 i i ii+* Re: realloc() - frequency, conditions, or experiences about relocation?7Malcolm McLean
19 Jun 24 i i iii+* Re: realloc() - frequency, conditions, or experiences about relocation?4Ben Bacarisse
19 Jun 24 i i iiii`* Re: realloc() - frequency, conditions, or experiences about relocation?3David Brown
19 Jun 24 i i iiii `* Re: realloc() - frequency, conditions, or experiences about relocation?2Ben Bacarisse
20 Jun 24 i i iiii  `- Re: realloc() - frequency, conditions, or experiences about relocation?1David Brown
20 Jun 24 i i iii`* Re: realloc() - frequency, conditions, or experiences about relocation?2Anton Shepelev
8 Jul 24 i i iii `- Re: realloc() - frequency, conditions, or experiences about relocation?1Anton Shepelev
19 Jun 24 i i ii`- Re: realloc() - frequency, conditions, or experiences about relocation?1Anton Shepelev
2 Jul 24 i i i`* Re: realloc() - frequency, conditions, or experiences about relocation?12Rich Ulrich
2 Jul 24 i i i +* Re: realloc() - frequency, conditions, or experiences about relocation?5Keith Thompson
2 Jul 24 i i i i`* Re: realloc() - frequency, conditions, or experiences about relocation?4Rich Ulrich
8 Jul 24 i i i i `* Re: realloc() - frequency, conditions, or experiences about relocation?3Anton Shepelev
22 Jul 24 i i i i  `* Re: realloc() - frequency, conditions, or experiences about relocation?2Rich Ulrich
23 Jul 24 i i i i   `- Re: realloc() - frequency, conditions, or experiences about relocation?1Anton Shepelev
2 Jul 24 i i i `* Re: realloc() - frequency, conditions, or experiences about relocation?6Paul
2 Jul 24 i i i  `* Re: realloc() - frequency, conditions, or experiences about relocation?5Rich Ulrich
2 Jul 24 i i i   `* Re: realloc() - frequency, conditions, or experiences about relocation?4Rich Ulrich
2 Jul 24 i i i    `* Re: realloc() - frequency, conditions, or experiences about relocation?3Paul
2 Jul 24 i i i     +- Re: realloc() - frequency, conditions, or experiences about relocation?1James Kuyper
2 Jul 24 i i i     `- Re: realloc() - frequency, conditions, or experiences about relocation?1James Kuyper
17 Jun 24 i i +- Re: realloc() - frequency, conditions, or experiences about relocation?1Chris M. Thomasson
18 Jun 24 i i `* Re: realloc() - frequency, conditions, or experiences about relocation?3Keith Thompson
18 Jun 24 i i  +- Re: realloc() - frequency, conditions, or experiences about relocation?1Malcolm McLean
18 Jun 24 i i  `- Re: realloc() - frequency, conditions, or experiences about relocation?1Bonita Montero
17 Jun 24 i `- Re: realloc() - frequency, conditions, or experiences about relocation?1David Brown
17 Jun 24 +* Re: realloc() - frequency, conditions, or experiences about relocation?28Bonita Montero
20 Jun 24 i`* Re: realloc() - frequency, conditions, or experiences about relocation?27Vir Campestris
21 Jun 24 i `* Re: realloc() - frequency, conditions, or experiences about relocation?26Bonita Montero
24 Jun 24 i  `* Re: realloc() - frequency, conditions, or experiences about relocation?25Lawrence D'Oliveiro
24 Jun 24 i   +* Re: realloc() - frequency, conditions, or experiences about relocation?21Keith Thompson
24 Jun 24 i   i+* Re: realloc() - frequency, conditions, or experiences about relocation?11David Brown
24 Jun 24 i   ii+* Re: realloc() - frequency, conditions, or experiences about relocation?7Malcolm McLean
24 Jun 24 i   iii+* Re: realloc() - frequency, conditions, or experiences about relocation?3Keith Thompson
25 Jun 24 i   iiii+- Re: realloc() - frequency, conditions, or experiences about relocation?1Malcolm McLean
25 Jun 24 i   iiii`- Re: realloc() - frequency, conditions, or experiences about relocation?1Chris M. Thomasson
25 Jun 24 i   iii`* Re: realloc() - frequency, conditions, or experiences about relocation?3Lawrence D'Oliveiro
25 Jun 24 i   iii `* Re: realloc() - frequency, conditions, or experiences about relocation?2Bonita Montero
26 Jun 24 i   iii  `- Re: realloc() - frequency, conditions, or experiences about relocation?1Lawrence D'Oliveiro
24 Jun 24 i   ii+* Re: realloc() - frequency, conditions, or experiences about relocation?2Chris M. Thomasson
24 Jun 24 i   iii`- Re: realloc() - frequency, conditions, or experiences about relocation?1Bonita Montero
25 Jun 24 i   ii`- Re: realloc() - frequency, conditions, or experiences about relocation?1Lawrence D'Oliveiro
24 Jun 24 i   i+- Re: realloc() - frequency, conditions, or experiences about relocation?1Bonita Montero
25 Jun 24 i   i`* Re: realloc() - frequency, conditions, or experiences about relocation?8Lawrence D'Oliveiro
25 Jun 24 i   i +* Re: realloc() - frequency, conditions, or experiences about relocation?6Keith Thompson
25 Jun 24 i   i i+- Re: realloc() - frequency, conditions, or experiences about relocation?1Richard Damon
28 Jun 24 i   i i+* Re: realloc() - frequency, conditions, or experiences about relocation?2Phil Carmody
28 Jun 24 i   i ii`- Re: realloc() - frequency, conditions, or experiences about relocation?1Keith Thompson
28 Jun 24 i   i i`* Re: realloc() - frequency, conditions, or experiences about relocation?2James Kuyper
28 Jun 24 i   i i `- Re: realloc() - frequency, conditions, or experiences about relocation?1Keith Thompson
28 Jun 24 i   i `- Re: realloc() - frequency, conditions, or experiences about relocation?1James Kuyper
24 Jun 24 i   `* Re: realloc() - frequency, conditions, or experiences about relocation?3Bonita Montero
24 Jun 24 i    `* Down the hall, past the water cooler, third door on the left... (Was: realloc() - frequency, conditions, or experiences about) relocation?2Kenny McCormack
24 Jun 24 i     `- Re: Down the hall, past the water cooler, third door on the left... (Was: realloc() - frequency, conditions, or experiences about) relocation?1Bonita Montero
17 Jun 24 +* Re: realloc() - frequency, conditions, or experiences about relocation?2David Brown
17 Jun 24 i`- Re: realloc() - frequency, conditions, or experiences about relocation?1Bonita Montero
17 Jun 24 +- Re: realloc() - frequency, conditions, or experiences about relocation?1Janis Papanagnou
17 Jun 24 +- Re: realloc() - frequency, conditions, or experiences about relocation?1Michael S
18 Jun 24 +- Re: realloc() - frequency, conditions, or experiences about relocation?1Rosario19
25 Jun 24 `* Re: realloc() - frequency, conditions, or experiences about relocation?7Bonita Montero
25 Jun 24  +* Re: realloc() - frequency, conditions, or experiences about relocation?4Vir Campestris
25 Jun 24  i`* Re: realloc() - frequency, conditions, or experiences about relocation?3Bonita Montero
26 Jun 24  i `* Re: realloc() - frequency, conditions, or experiences about relocation?2Vir Campestris
26 Jun 24  i  `- Re: realloc() - frequency, conditions, or experiences about relocation?1Bonita Montero
25 Jun 24  `* Re: realloc() - frequency, conditions, or experiences about relocation?2DFS
25 Jun 24   `- Re: realloc() - frequency, conditions, or experiences about relocation?1Bonita Montero

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal