mem alloc change #1

This commit is contained in:
albert 2002-10-13 07:28:51 +00:00
parent bdf87326d2
commit 44d77559ad

23
top.c
View File

@ -1740,18 +1740,18 @@ static void cpudo (CPUS_t *cpu, const char *pfx)
* AND establish the total number of tasks for this frame! */ * AND establish the total number of tasks for this frame! */
static void frame_states (proc_t **ppt, int show) static void frame_states (proc_t **ppt, int show)
{ {
static HIST_t *hist_sav = NULL; static HIST_t *hist_sav;
static unsigned hist_siz; static unsigned hist_siz; // number of structs
HIST_t *hist_new; HIST_t *hist_new;
unsigned total, running, sleeping, stopped, zombie; unsigned total, running, sleeping, stopped, zombie;
int i; int i;
if (!hist_sav) { if (!hist_sav) {
Frame_maxtask = 0; Frame_maxtask = 0;
hist_siz = (Page_size / sizeof(HIST_t)); hist_siz = 100;
hist_sav = alloc_c(hist_siz); hist_sav = alloc_c(sizeof(HIST_t)*hist_siz);
} }
hist_new = alloc_c(hist_siz); hist_new = alloc_c(sizeof(HIST_t)*hist_siz);
total = running = sleeping = stopped = zombie = 0; total = running = sleeping = stopped = zombie = 0;
time_elapsed(); time_elapsed();
@ -1775,10 +1775,10 @@ static void frame_states (proc_t **ppt, int show)
running++; running++;
break; break;
} }
if (total * sizeof(HIST_t) >= hist_siz) { if (total >= hist_siz) {
hist_siz += (Page_size / sizeof(HIST_t)); hist_siz = hist_siz * 5 / 4 + 1; // grow by at least 25%
hist_sav = alloc_r(hist_sav, hist_siz); hist_sav = alloc_r(hist_sav, sizeof(HIST_t)*hist_siz);
hist_new = alloc_r(hist_new, hist_siz); hist_new = alloc_r(hist_new, sizeof(HIST_t)*hist_siz);
} }
/* calculate time in this process; the sum of user time (utime) /* calculate time in this process; the sum of user time (utime)
+ system time (stime) -- but PLEASE dont waste time and effort on + system time (stime) -- but PLEASE dont waste time and effort on
@ -1825,9 +1825,8 @@ static void frame_states (proc_t **ppt, int show)
} }
} /* end: if 'show' */ } /* end: if 'show' */
/* save this frame's information */ free(hist_sav);
memcpy(hist_sav, hist_new, hist_siz); hist_sav = hist_new;
free(hist_new);
/* shout results to the world (and us too, the next time around) */ /* shout results to the world (and us too, the next time around) */
Frame_maxtask = total; Frame_maxtask = total;
} }