don't play fast and loose with memory block allcation. try to allocate

in more-round sizes, but realize that not everybody will fill them up
exactly.
This commit is contained in:
cgd 1994-12-23 13:21:01 +00:00
parent db1ae625b5
commit e9aebcc9d8

View File

@ -36,7 +36,7 @@
#ifndef lint
/*static char sccsid[] = "from: @(#)memalloc.c 8.1 (Berkeley) 5/31/93";*/
static char *rcsid = "$Id: memalloc.c,v 1.10 1994/12/04 07:12:19 cgd Exp $";
static char *rcsid = "$Id: memalloc.c,v 1.11 1994/12/23 13:21:01 cgd Exp $";
#endif /* not lint */
#include "shell.h"
@ -100,12 +100,9 @@ savestr(s)
* Parse trees for commands are allocated in lifo order, so we use a stack
* to make this more efficient, and also to avoid all sorts of exception
* handling code to handle interrupts in the middle of a parse.
*
* The size 504 was chosen because the Ultrix malloc handles that size
* well.
*/
#define MINSIZE 504 /* minimum size of a block */
#define MINSIZE 512 /* minimum size of a block */
struct stack_block {
@ -127,17 +124,19 @@ stalloc(nbytes)
int nbytes;
{
register char *p;
int roundbytes;
nbytes = ALIGN(nbytes);
if (nbytes > stacknleft) {
roundbytes = ALIGN(nbytes);
if (roundbytes > stacknleft) {
int blocksize;
struct stack_block *sp;
blocksize = nbytes;
blocksize = roundbytes;
if (blocksize < MINSIZE)
blocksize = MINSIZE;
INTOFF;
sp = ckmalloc(sizeof(struct stack_block) - MINSIZE + blocksize);
memmove(sp->space, stacknxt, nbytes);
sp->prev = stackp;
stacknxt = sp->space;
stacknleft = blocksize;
@ -145,8 +144,8 @@ stalloc(nbytes)
INTON;
}
p = stacknxt;
stacknxt += nbytes;
stacknleft -= nbytes;
stacknxt += roundbytes;
stacknleft -= roundbytes;
return p;
}
@ -206,7 +205,7 @@ popstackmark(mark)
void
growstackblock() {
char *p;
int newlen = stacknleft * 2 + 100;
int newlen = stacknleft * 2 + 128;
char *oldspace = stacknxt;
int oldlen = stacknleft;
struct stack_block *sp;