MCPcopy Index your code
hub / github.com/3proxy/3proxy / myalloc

Function myalloc

src/myalloc.c:93–214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91int alloced = 0;
92
93void * myalloc(size_t size){
94 struct mempage *newpage, *page;
95 unsigned pagesize;
96 unsigned i=0, j, k=0;
97 int p;
98
99
100 alloced++;
101 if(!mem_init)init_mem();
102 for(p = nomem; ; ) {
103 if(!p){
104#if DEBUGLEVEL > 2
105fprintf(stderr, "Page is too large (%u), requesting malloc instead\n", size);
106fflush(stderr);
107#endif
108 return malloc(size);
109 }
110 p--;
111 if(size<memsizes[p]){
112 break;
113 }
114 }
115
116 if(p == p64k){
117#if DEBUGLEVEL > 2
118fprintf(stderr, "Page will p64k\n");
119fflush(stderr);
120#endif
121 return myalloc64k();
122 }
123
124 pagesize = memsizes[p];
125#if DEBUGLEVEL > 2
126fprintf(stderr, "Calculated pagesize: %u\n", pagesize);
127fflush(stderr);
128#endif
129 pthread_mutex_lock(&mem_mutex);
130 newpage = pages[p];
131 if(newpage && newpage->usable){
132#if DEBUGLEVEL > 2
133fprintf(stderr, "Useful page found: %X,", newpage);
134fflush(stderr);
135#endif
136 for(j=0; j<32; j++){
137 register unsigned c = newpage->bitmap[j];
138 if(c){
139 for(k=0; ;k++)if(c & (1<<k))break;
140 i = (j<<11) + (k<<8);
141#if DEBUGLEVEL > 2
142fprintf(stderr, "region: %X, offset %u, byte %u, %u, %u\n", newpage->data + i, i, j, k, newpage->bitmap[j]);
143fflush(stderr);
144#endif
145 break;
146 }
147 }
148 }
149 else{
150 if(!(newpage = (struct mempage *)malloc(sizeof(struct mempage)))){

Callers 15

proxymain.cFile · 0.85
itcopyFunction · 0.85
copyfilterFunction · 0.85
makefiltersFunction · 0.85
proxychildFunction · 0.85
sockmapFunction · 0.85
dnsprchildFunction · 0.85
clientnegotiateFunction · 0.85
doauthFunction · 0.85
inithashtableFunction · 0.85
adminchildFunction · 0.85
mystrdupFunction · 0.85

Calls 2

init_memFunction · 0.85
myalloc64kFunction · 0.85

Tested by

no test coverage detected