From a8a0ef3c4d10bf576054dc26348d9b4e6efeecc2 Mon Sep 17 00:00:00 2001 From: scw Date: Thu, 9 Sep 2004 12:45:10 +0000 Subject: Using mmap instead of alloca to get buffer when CRITICAL_MEMORY is defined. git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2185 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/brc.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/mbbsd/brc.c b/mbbsd/brc.c index b3be8101..7e61e578 100644 --- a/mbbsd/brc.c +++ b/mbbsd/brc.c @@ -133,13 +133,34 @@ brc_enlarge_buf() char *buffer; if (brc_alloc >= BRC_MAXSIZE) return 0; - buffer = (char*)alloca(brc_alloc); + +#ifdef CRITICAL_MEMORY +#define THE_MALLOC(X) MALLOC(X) +#define THE_FREE(X) FREE(X) +#else +#define THE_MALLOC(X) alloca(X) +#define THE_FREE(X) (void)(X) + /* alloca get memory from stack and automatically freed when + * function returns. */ +#endif + + buffer = (char*)THE_MALLOC(brc_alloc); + memcpy(buffer, brc_buf, brc_alloc); free(brc_buf); brc_alloc += BRC_BLOCKSIZE; brc_buf = (char*)malloc(brc_alloc); memcpy(brc_buf, buffer, brc_alloc - BRC_BLOCKSIZE); + +#ifdef DEBUG + vmsg("brc enlarged to %d bytes", brc_alloc); +#endif + + THE_FREE(buffer); return 1; + +#undef THE_MALLOC +#undef THE_FREE } static inline void -- cgit v1.2.3