we do not need the group backpointer, except for a (very little) amount
of sanitising; since this is supposed to be the lightweight allocator, with the guarding allocator coming back in later, remove it reduces memory consumption below what espie's allocator used ☺
This commit is contained in:
parent
44202462f5
commit
ebfce0fafd
15
lalloc.c
15
lalloc.c
@ -1,6 +1,6 @@
|
|||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/lalloc.c,v 1.3 2009/03/23 10:31:15 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/lalloc.c,v 1.4 2009/03/24 08:37:37 tg Exp $");
|
||||||
|
|
||||||
#ifndef SIZE_MAX
|
#ifndef SIZE_MAX
|
||||||
#ifdef SIZE_T_MAX
|
#ifdef SIZE_T_MAX
|
||||||
@ -12,7 +12,6 @@ __RCSID("$MirOS: src/bin/mksh/lalloc.c,v 1.3 2009/03/23 10:31:15 tg Exp $");
|
|||||||
|
|
||||||
struct lalloc {
|
struct lalloc {
|
||||||
struct lalloc *next; /* entry pointer, must be first */
|
struct lalloc *next; /* entry pointer, must be first */
|
||||||
Area *group; /* group backpointer */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void findptr(struct lalloc **, struct lalloc **, char *, Area *);
|
static void findptr(struct lalloc **, struct lalloc **, char *, Area *);
|
||||||
@ -27,13 +26,10 @@ static void
|
|||||||
findptr(struct lalloc **lpp, struct lalloc **ppp, char *ptr, Area *ap)
|
findptr(struct lalloc **lpp, struct lalloc **ppp, char *ptr, Area *ap)
|
||||||
{
|
{
|
||||||
*lpp = (struct lalloc *)(ptr - sizeof (struct lalloc));
|
*lpp = (struct lalloc *)(ptr - sizeof (struct lalloc));
|
||||||
if ((*lpp)->group != ap)
|
|
||||||
notfound:
|
|
||||||
internal_errorf("pointer %p not in group %p", ptr, ap);
|
|
||||||
*ppp = (struct lalloc *)ap;
|
*ppp = (struct lalloc *)ap;
|
||||||
while ((*ppp)->next != *lpp)
|
while ((*ppp)->next != *lpp)
|
||||||
if (((*ppp) = (*ppp)->next) == NULL)
|
if (((*ppp) = (*ppp)->next) == NULL)
|
||||||
goto notfound;
|
internal_errorf("pointer %p not in group %p", ptr, ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
@ -57,7 +53,6 @@ aresize(void *ptr, size_t numb, Area *ap)
|
|||||||
(unsigned long)numb);
|
(unsigned long)numb);
|
||||||
}
|
}
|
||||||
if (ptr == NULL) {
|
if (ptr == NULL) {
|
||||||
lp->group = ap;
|
|
||||||
lp->next = ap->ent;
|
lp->next = ap->ent;
|
||||||
}
|
}
|
||||||
pp->next = lp;
|
pp->next = lp;
|
||||||
@ -74,7 +69,6 @@ afree(void *ptr, Area *ap)
|
|||||||
|
|
||||||
findptr(&lp, &pp, ptr, ap);
|
findptr(&lp, &pp, ptr, ap);
|
||||||
pp->next = lp->next;
|
pp->next = lp->next;
|
||||||
/* lp->group = NULL; */
|
|
||||||
free(lp);
|
free(lp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,12 +78,7 @@ afreeall(Area *ap)
|
|||||||
struct lalloc *lp;
|
struct lalloc *lp;
|
||||||
|
|
||||||
while ((lp = ap->ent) != NULL) {
|
while ((lp = ap->ent) != NULL) {
|
||||||
#ifndef MKSH_SMALL
|
|
||||||
if (lp->group != ap)
|
|
||||||
internal_errorf("rogue pointer in group %p", ap);
|
|
||||||
#endif
|
|
||||||
ap->ent = lp->next;
|
ap->ent = lp->next;
|
||||||
/* lp->group = NULL; */
|
|
||||||
free(lp);
|
free(lp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user