summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-03-15 20:26:18 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-03-15 20:26:18 +0800
commita4b817990639a49e6e7fa40f718ce01288adba28 (patch)
tree4d0a76fa26a4c64007c9d1c466d0f701dc214ed9
parentc08ffd0a8ca09b3bb2ca5d8f38ae0cb275e17e0d (diff)
downloadpttbbs-a4b817990639a49e6e7fa40f718ce01288adba28.tar
pttbbs-a4b817990639a49e6e7fa40f718ce01288adba28.tar.gz
pttbbs-a4b817990639a49e6e7fa40f718ce01288adba28.tar.bz2
pttbbs-a4b817990639a49e6e7fa40f718ce01288adba28.tar.lz
pttbbs-a4b817990639a49e6e7fa40f718ce01288adba28.tar.xz
pttbbs-a4b817990639a49e6e7fa40f718ce01288adba28.tar.zst
pttbbs-a4b817990639a49e6e7fa40f718ce01288adba28.zip
save memory usage of nbrd in CRITICAL_MEMORY mode
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@696 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--pttbbs/mbbsd/board.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c
index e8fbe5ca..e2950b28 100644
--- a/pttbbs/mbbsd/board.c
+++ b/pttbbs/mbbsd/board.c
@@ -1,4 +1,4 @@
-/* $Id: board.c,v 1.85 2003/03/15 12:06:39 in2 Exp $ */
+/* $Id: board.c,v 1.86 2003/03/15 12:26:18 in2 Exp $ */
#include "bbs.h"
#define BRC_STRLEN 15 /* Length of board name */
#define BRC_MAXSIZE 24576
@@ -230,7 +230,10 @@ char zapchange = 0, favchange = 0, choose_board_depth = 0;
#define STR_FAV ".fav"
#define STR_FAV2 ".fav2"
-#ifdef CRITICAL_MEMORY
+#ifndef CRITICAL_MEMORY
+ #define MALLOC(p) malloc(p)
+ #define FREE(p) free(p)
+#else
void *MALLOC(int size)
{
int *p;
@@ -537,6 +540,9 @@ load_boards(char *key)
int type = cuser.uflag & BRDSORT_FLAG ? 1 : 0;
register int i, n;
register int state;
+#ifdef CRITICAL_MEMORY
+ boardstat_t *tmpnbrd;
+#endif
if (class_bid > 0) {
bptr = &bcache[class_bid - 1];
@@ -549,7 +555,7 @@ load_boards(char *key)
nbrd = NULL;
}
if (class_bid <= 0) {
- nbrd = (boardstat_t *) malloc(sizeof(boardstat_t) * numboards);
+ nbrd = (boardstat_t *) MALLOC(sizeof(boardstat_t) * numboards);
for (i = 0; i < numboards; i++) {
if ((bptr = SHM->bsorted[type][i]) == NULL)
continue;
@@ -565,9 +571,8 @@ load_boards(char *key)
}
if (class_bid == -1)
qsort(nbrd, brdnum, sizeof(boardstat_t), cmpboardfriends);
- nbrd = realloc(nbrd, sizeof(boardstat_t) * brdnum);
} else {
- nbrd = (boardstat_t *) malloc(bptr->childcount * sizeof(boardstat_t));
+ nbrd = (boardstat_t *) MALLOC(bptr->childcount * sizeof(boardstat_t));
for (bptr = bptr->firstchild[type]; bptr != (boardheader_t *) ~ 0;
bptr = bptr->next[type]) {
n = (int)(bptr - bcache);
@@ -578,8 +583,15 @@ load_boards(char *key)
continue;
addnewbrdstat(n, state);
}
- nbrd = realloc(nbrd, sizeof(boardstat_t) * brdnum);
}
+#ifndef CRITICAL_MEMORY
+ nbrd = realloc(nbrd, sizeof(boardstat_t) * brdnum);
+#else
+ tmpnbrd = (boardstat_t *) malloc(sizeof(boardstat_t) * brdnum);
+ memcpy(tmpnbrd, nbrd, sizeof(boardstat_t) * brdnum);
+ FREE(nbrd);
+ nbrd = tmpnbrd;
+#endif
}
static int