Skip to content

Commit

Permalink
Merge pull request #2177 from ghaerr/fmalloc2
Browse files Browse the repository at this point in the history
[libc] Don't call sysctl every malloc, set DEBUG=1 default in fmalloc
  • Loading branch information
ghaerr authored Jan 9, 2025
2 parents 9f26e1e + 7a42f7f commit e9e445d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion libc/malloc/dmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ _dmalloc(size_t nbytes)
unsigned int nw, temp;

#if DEBUG == 1
sysctl(CTL_GET, "malloc.debug", &debug_level);
if (debug_level == 1) sysctl(CTL_GET, "malloc.debug", &debug_level);
#endif
if (allocs[0].ptr == 0) { /*first time*/
allocs[0].ptr = setbusy(&allocs[1]);
Expand Down
6 changes: 3 additions & 3 deletions libc/malloc/fmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <unistd.h>
#include <errno.h>
#include <sys/sysctl.h>
#define DEBUG 0 /* =1 use sysctl, =2 debug output, =3 show heap */
#define DEBUG 1 /* =1 use sysctl, =2 debug output, =3 show heap */

/* C storage allocator
* circular first-fit strategy
Expand Down Expand Up @@ -110,7 +110,7 @@ _fmalloc(size_t nbytes)
unsigned int nw, temp;

#if DEBUG == 1
sysctl(CTL_GET, "malloc.debug", &debug_level);
if (debug_level == 1) sysctl(CTL_GET, "malloc.debug", &debug_level);
#endif

debug("(%d)malloc(%5u) ", getpid(), nbytes);
Expand All @@ -137,7 +137,7 @@ _fmalloc(size_t nbytes)
/* combine free areas at heap start before allocating from free area past allocp */
//allocp = (NPTR)allocs; /* NOTE: start at last allocation for speed */
for(p=allocp; ; ) {
//f = nb = n = 0;
//int f = 0, nb = 0, n = 0;
for(temp=0; ; ) {
if(!testbusy(next(p))) {
while(!testbusy(next(q = next(p)))) {
Expand Down

0 comments on commit e9e445d

Please sign in to comment.