Vastly decrease amount of memory comsumed in the case when we have to read

ports/INDEX, by allocating eactly amount of memory necessary for storing
each particular entry, insdead of 4K per entry (more than 7000 entries -
go figure). Memory consumption went down to some 500K from some 30M.
This commit is contained in:
Maxim Sobolev 2002-09-09 08:00:32 +00:00
parent 6478b242d6
commit d4f82fcf34
2 changed files with 11 additions and 4 deletions

View file

@ -68,6 +68,8 @@ pkg_perform(char **indexarg)
i = -1;
while (pkgs[++i] != NULL) {
if (MatchName == NULL || strstr(pkgs[i], MatchName))
if (strcmp(pkgs[i], "mpeg_lib-1.3.1") == 0)
printf("Found!\n");
err_cnt += pkg_do(pkgs[i]);
}
@ -75,6 +77,10 @@ pkg_perform(char **indexarg)
while (!SLIST_EMPTY(&Index)) {
ie = SLIST_FIRST(&Index);
SLIST_REMOVE_HEAD(&Index, next);
if (ie->name != NULL)
free(ie->name);
if (ie->origin != NULL)
free(ie->origin);
free(ie);
}
if (IndexFile != NULL)
@ -157,8 +163,9 @@ pkg_do(char *pkg)
errx(2, "The INDEX does not appear to be valid!");
if ((ie = malloc(sizeof(struct index_entry))) == NULL)
errx(2, "Unable to allocate memory in %s.", __func__);
strlcpy(ie->name, tmp, PATH_MAX);
strlcpy(ie->origin, &ch[1], PATH_MAX);
bzero(ie, sizeof(struct index_entry));
ie->name = strdup(tmp);
ie->origin = strdup(&ch[1]);
/* Who really cares if we reverse the index... */
SLIST_INSERT_HEAD(&Index, ie, next);
}

View file

@ -32,8 +32,8 @@
struct index_entry {
SLIST_ENTRY(index_entry) next;
char name[PATH_MAX];
char origin[PATH_MAX];
char *name;
char *origin;
};
SLIST_HEAD(index_head, index_entry);