]> 4ch.mooo.com Git - 16.git/blob - src/lib/16_hc.c
added some stuff i got tired of adding w and some more and thats it for that i will...
[16.git] / src / lib / 16_hc.c
1 /* Project 16 Source Code~\r
2  * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
3  *\r
4  * This file is part of Project 16.\r
5  *\r
6  * Project 16 is free software; you can redistribute it and/or modify\r
7  * it under the terms of the GNU General Public License as published by\r
8  * the Free Software Foundation; either version 3 of the License, or\r
9  * (at your option) any later version.\r
10  *\r
11  * Project 16 is distributed in the hope that it will be useful,\r
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  * GNU General Public License for more details.\r
15  *\r
16  * You should have received a copy of the GNU General Public License\r
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>, or\r
18  * write to the Free Software Foundation, Inc., 51 Franklin Street,\r
19  * Fifth Floor, Boston, MA 02110-1301 USA.\r
20  *\r
21  */\r
22 /*\r
23         heap check\r
24 */\r
25 \r
26 #include "src/lib/16_hc.h"\r
27 #include <malloc.h>\r
28 \r
29 //from ftp://213.85.246.177/pub/FreeBSD/ports/archivers/arj/work/arj-3.10.22/environ.c\r
30 #if 0\r
31 //#ifdef __WATCOMC__\r
32 long HC_Newfarcoreleft()\r
33 {\r
34         void __huge *hp;                static long rc=736L;    long s_rc;\r
35 \r
36         s_rc=rc;        rc+=2L;\r
37         do\r
38                 hp=halloc(rc-=2L, 1024);\r
39         while(hp==NULL&&rc>0L);\r
40         if(hp!=NULL)\r
41                 hfree(hp);\r
42         if(rc<s_rc)\r
43                 return(rc*1024L);\r
44         do\r
45         {\r
46                 hp=halloc(rc+=16L, 1024);\r
47                 if(hp!=NULL)\r
48                         hfree(hp);\r
49         } while(hp!=NULL);\r
50         return((rc-16L)*1024L);\r
51 }\r
52 #endif\r
53 \r
54 //from: https://stackoverflow.com/questions/14386856/c-check-available-ram\r
55 void __near* HC_LargestFreeBlock(size_t* Size)\r
56 {\r
57         size_t s0, s1;\r
58         void __near* p;\r
59 \r
60         s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);\r
61         while (s0 && (p = _nmalloc(s0)) == NULL)\r
62                 s0 >>= 1;\r
63 \r
64         if (p)\r
65                 _nfree(p);\r
66 \r
67         s1 = s0 >> 1;\r
68         while (s1)\r
69         {\r
70                 if ((p = _nmalloc(s0 + s1)) != NULL)\r
71                 {\r
72                         s0 += s1;\r
73                         _nfree(p);\r
74                 }\r
75         s1 >>= 1;\r
76         }\r
77         while (s0 && (p = _nmalloc(s0)) == NULL)\r
78                 s0 ^= s0 & -s0;\r
79 \r
80         *Size = s0;\r
81         return p;\r
82 }\r
83 \r
84 //from: https://stackoverflow.com/questions/14386856/c-check-available-ram\r
85 size_t HC_coreleft(void)\r
86 {\r
87         size_t total = 0;\r
88         void __near* pFirst = NULL;\r
89         void __near* pLast = NULL;\r
90         for(;;)\r
91         {\r
92                 size_t largest;\r
93                 void __near* p = (void __near *)HC_LargestFreeBlock(&largest);\r
94                 if (largest < sizeof(void __near*))\r
95                 {\r
96                         if (p != NULL)\r
97                         _nfree(p);\r
98                         break;\r
99                 }\r
100                 *(void __near* __near*)p = NULL;\r
101                 total += largest;\r
102                 if (pFirst == NULL)\r
103                         pFirst = p;\r
104 \r
105                 if (pLast != NULL)\r
106                         *(void __near* __near*)pLast = p;\r
107                 pLast = p;\r
108         }\r
109 \r
110         while (pFirst != NULL)\r
111         {\r
112                 void __near* p = *(void __near* __near*)pFirst;\r
113                 _nfree(pFirst);\r
114                 pFirst = p;\r
115         }\r
116         return total;\r
117 }\r
118 \r
119 //far version of above\r
120 void __far* HC_LargestFarFreeBlock(dword* Size)\r
121 {\r
122         dword s0, s1;\r
123         void __far* p;\r
124 \r
125         s0 = ~(dword)0 ^ (~(dword)0 >> 1);\r
126         while (s0 && (p = _fmalloc(s0)) == NULL)\r
127                 s0 >>= 1;\r
128 \r
129         if (p)\r
130                 _ffree(p);\r
131 \r
132         s1 = s0 >> 1;\r
133         while (s1)\r
134         {\r
135                 if ((p = _fmalloc(s0 + s1)) != NULL)\r
136                 {\r
137                         s0 += s1;\r
138                         _ffree(p);\r
139                 }\r
140         s1 >>= 1;\r
141         }\r
142         while (s0 && (p = _fmalloc(s0)) == NULL)\r
143                 s0 ^= s0 & -s0;\r
144 \r
145         *Size = s0;\r
146         return p;\r
147 }\r
148 \r
149 //far version of above\r
150 dword HC_farcoreleft(void)\r
151 {\r
152         dword total = 0UL;\r
153         void __far* pFirst = NULL;\r
154         void __far* pLast = NULL;\r
155         for(;;)\r
156         {\r
157                 dword largest;\r
158                 void __far* p = HC_LargestFarFreeBlock(&largest);\r
159                 if (largest < sizeof(void __far*))\r
160                 {\r
161                         if (p != NULL)\r
162                         _ffree(p);\r
163                         break;\r
164                 }\r
165                 *(void __far* __far*)p = NULL;\r
166                 total += largest;\r
167                 if (pFirst == NULL)\r
168                         pFirst = p;\r
169 \r
170                 if (pLast != NULL)\r
171                         *(void __far* __far*)pLast = p;\r
172                 pLast = p;\r
173         }\r
174 \r
175         while (pFirst != NULL)\r
176         {\r
177                 void __far* p = *(void __far* __far*)pFirst;\r
178                 _ffree(pFirst);\r
179                 pFirst = p;\r
180         }\r
181 \r
182         //if(total>16) total+=16;       total &= 0xfffffff0UL;\r
183         return total;\r
184 }\r
185 \r
186 //==#ifdef __WATCOMC__\r
187 /*void huge* LargestHugeFreeBlock(size_t* Size)\r
188 {\r
189         size_t s0, s1;\r
190         void huge* p;\r
191 \r
192         s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);\r
193         while (s0 && (p = halloc((dword)s0, 1)) == NULL)\r
194                 s0 >>= 1;\r
195 \r
196         if (p)\r
197                 hfree(p);\r
198 \r
199         s1 = s0 >> 1;\r
200         while (s1)\r
201         {\r
202                 if ((p = halloc((dword)(s0 + s1), 1)) != NULL)\r
203                 {\r
204                         s0 += s1;\r
205                         hfree(p);\r
206                 }\r
207         s1 >>= 1;\r
208         }\r
209         while (s0 && (p = halloc((dword)s0, 1)) == NULL)\r
210                 s0 ^= s0 & -s0;\r
211 \r
212         *Size = s0;\r
213         return p;\r
214 }\r
215 \r
216 size_t _hugecoreleft(void)\r
217 {\r
218         size_t total = 0;\r
219         void huge* pFirst = NULL;\r
220         void huge* pLast = NULL;\r
221         for(;;)\r
222         {\r
223                 size_t largest;\r
224                 void huge* p = LargestHugeFreeBlock(&largest);\r
225                 if (largest < sizeof(void huge*))\r
226                 {\r
227                         if (p != NULL)\r
228                         hfree(p);\r
229                         break;\r
230                 }\r
231                 *(void huge* huge*)p = NULL;\r
232                 total += largest;\r
233                 if (pFirst == NULL)\r
234                         pFirst = p;\r
235 \r
236                 if (pLast != NULL)\r
237                         *(void huge* huge*)pLast = p;\r
238                 pLast = p;\r
239         }\r
240 \r
241         while (pFirst != NULL)\r
242         {\r
243                 void huge* p = *(void huge* huge*)pFirst;\r
244                 hfree(pFirst);\r
245                 pFirst = p;\r
246         }\r
247         return total;\r
248 }\r
249 \r
250 void __based(__self)* LargestBasedFreeBlock(size_t* Size)\r
251 {\r
252         __segment segu;\r
253         size_t s0, s1;\r
254         void __based(__self)* p;\r
255 \r
256         s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);\r
257         while (s0 && (p = _bmalloc(segu, s0)) == NULL)\r
258                 s0 >>= 1;\r
259 \r
260         if (p)\r
261                 _ffree(p);\r
262 \r
263         s1 = s0 >> 1;\r
264         while (s1)\r
265         {\r
266                 if ((p = _bmalloc(segu, s0 + s1)) != NULL)\r
267                 {\r
268                         s0 += s1;\r
269                         _ffree(p);\r
270                 }\r
271         s1 >>= 1;\r
272         }\r
273         while (s0 && (p = _bmalloc(segu, s0)) == NULL)\r
274                 s0 ^= s0 & -s0;\r
275 \r
276         *Size = s0;\r
277         return p;\r
278 }\r
279 \r
280 size_t _basedcoreleft(void)\r
281 {\r
282         __segment segu;\r
283         size_t total = 0;\r
284         void __based(segu)* pFirst = NULL;\r
285         void __based(segu)* pLast = NULL;\r
286         // allocate based heap\r
287         segu = _bHC_heapseg( 1024 );\r
288         if( segu == _NULLSEG ) {\r
289                 printf( "Unable to allocate based heap\n" );\r
290                 return 0;\r
291 \r
292         }\r
293         else\r
294 \r
295         for(;;)\r
296         {\r
297                 size_t largest;\r
298                 void __based(segu)* p = LargestBasedFreeBlock(&largest);\r
299                 if (largest < sizeof(void __far*))\r
300                 {\r
301                         if (p != NULL)\r
302                         _ffree(p);\r
303                         break;\r
304                 }\r
305                 *(void __far* __far*)p = NULL;\r
306                 total += largest;\r
307                 if (pFirst == NULL)\r
308                         pFirst = p;\r
309 \r
310                 if (pLast != NULL)\r
311                         *(void __far* __far*)pLast = p;\r
312                 pLast = p;\r
313         }\r
314 \r
315         while (pFirst != NULL)\r
316         {\r
317                 void __far* p = *(void __far* __far*)pFirst;\r
318                 _ffree(pFirst);\r
319                 pFirst = p;\r
320         }\r
321         return total;\r
322 }\r
323 \r
324 size_t HC_GetFreeSize(void)\r
325 {\r
326         struct _heapinfo h_info;\r
327         int heap_status;\r
328         size_t h_free=0, h_total=0, h_used=0;\r
329 \r
330         h_info._pentry = NULL;\r
331         for(;;) {\r
332                 heap_status = _heapwalk( &h_info );\r
333                 if( heap_status != _HEAPOK ) break;\r
334                 if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") h_free += h_info._size;\r
335                 if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") h_used += h_info._size;\r
336                 h_total += h_info._size;\r
337         }\r
338         HCL_heapstat(heap_status);\r
339         return h_free;\r
340 }\r
341 */\r
342 \r
343 void HCL_HeapWalking (struct _heapinfo *h_info, hc_use_t *hu, unsigned nearfarswitch)\r
344 {\r
345         hu->h_free=0; hu->h_total=0; hu->h_used=0;\r
346 \r
347         h_info->_pentry = NULL;\r
348         for(;;) {\r
349                 if(nearfarswitch==0) hu->heap_status = _nheapwalk( h_info );\r
350                 else if(nearfarswitch==1) hu->heap_status = _fheapwalk( h_info );\r
351                 if( hu->heap_status != _HEAPOK ) break;\r
352                 if((h_info->_useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") hu->h_free += h_info->_size;\r
353                 if((h_info->_useflag == _USEDENTRY ? "USED" : "FREE")=="USED") hu->h_used += h_info->_size;\r
354                 hu->h_total += h_info->_size;\r
355         }\r
356         HCL_heapstat(hu->heap_status);\r
357 }\r
358 \r
359 dword HC_GetFarFreeSize(void)\r
360 {\r
361         struct _heapinfo h_info;\r
362         hc_use_t hu;\r
363         HCL_HeapWalking (&h_info, &hu, 1);\r
364         return hu.h_free;\r
365 #if 0\r
366         struct _heapinfo fh_info;\r
367         int heap_status;\r
368         dword fh_free=0, fh_total=0, fh_used=0;\r
369 \r
370         fh_info._pentry = NULL;\r
371         for(;;) {\r
372                 heap_status = _fheapwalk( &fh_info );\r
373                 if( heap_status != _HEAPOK ) break;\r
374                 if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") fh_free += fh_info._size;\r
375                 if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") fh_used += fh_info._size;\r
376                 fh_total += fh_info._size;\r
377         }\r
378         HCL_heapstat(heap_status);\r
379         return fh_free;\r
380 #endif\r
381 }\r
382 \r
383 size_t HC_GetNearFreeSize(void)\r
384 {\r
385         struct _heapinfo h_info;\r
386         hc_use_t hu;\r
387         HCL_HeapWalking (&h_info, &hu, 0);\r
388         return hu.h_free;\r
389 #if 0\r
390         struct _heapinfo nh_info;\r
391         int heap_status;\r
392         size_t nh_free=0, nh_total=0, nh_used=0;\r
393 \r
394         nh_info._pentry = NULL;\r
395         for(;;) {\r
396                 heap_status = _nheapwalk( &nh_info );\r
397                 if( heap_status != _HEAPOK ) break;\r
398                 if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") nh_free += nh_info._size;\r
399                 if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") nh_used += nh_info._size;\r
400                 nh_total += nh_info._size;\r
401         }\r
402         HCL_heapstat(heap_status);\r
403         return nh_free;\r
404 #endif\r
405 }\r
406 \r
407 void HC_heapdump(global_game_variables_t *gvar)\r
408 {\r
409         struct _heapinfo fh_info, nh_info;//, h_info;\r
410         int heap_status;\r
411         size_t nh_free, fh_free, nh_total, fh_total, nh_used, fh_used;//,       h_free, h_total, h_used;\r
412         byte    scratch[1024],str[16];\r
413 \r
414         HC_OpenDebug(gvar);\r
415 \r
416 #if 0\r
417         strcpy(scratch,"\n      == default ==\n\n");\r
418         write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
419         h_info._pentry = NULL;\r
420         h_free=0; h_total=0; h_used=0;\r
421         for(;;) {\r
422                 heap_status = _heapwalk( &h_info );\r
423                 if( heap_status != _HEAPOK ) break;\r
424                 strcpy(scratch,"  "); strcat(scratch,(h_info._useflag == _USEDENTRY ? "USED" : "FREE")); strcat(scratch," block at ");\r
425                 sprintf(str, "%Fp", h_info._pentry); //ultoa((dword)h_info._pentry,str,16);\r
426                         strcat(scratch,str); strcat(scratch," of size "); ultoa(h_info._size,str,10); strcat(scratch,str); strcat(scratch,"\n");\r
427                 if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") h_free += h_info._size;\r
428                 if((h_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") h_used += h_info._size;\r
429                 h_total += h_info._size;\r
430                 write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
431         }\r
432         HCL_heapstatLogWrite(gvar, heap_status, scratch);\r
433 #endif\r
434 \r
435         //near\r
436         strcpy(scratch,"\n      == near ==\n\n");\r
437         write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
438         nh_info._pentry = NULL;\r
439         nh_free=0; nh_total=0; nh_used=0;\r
440         for(;;) {\r
441                 heap_status = _nheapwalk( &nh_info );\r
442                 if( heap_status != _HEAPOK ) break;\r
443                 strcpy(scratch,"  "); strcat(scratch,(nh_info._useflag == _USEDENTRY ? "USED" : "FREE")); strcat(scratch," block at ");\r
444                 sprintf(str, "%Fp", nh_info._pentry); //ultoa((dword)nh_info._pentry,str,16);\r
445                         strcat(scratch,str); strcat(scratch," of size "); ultoa(nh_info._size,str,10); strcat(scratch,str); strcat(scratch,"\n");\r
446 /*              printf( "  %s block at %Fp of size %4.4X\n",\r
447 (nh_info._useflag == _USEDENTRY ? "USED" : "FREE"),\r
448 nh_info._pentry, nh_info._size );*/\r
449                 if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") nh_free += nh_info._size;\r
450                 if((nh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") nh_used += nh_info._size;\r
451                 nh_total += nh_info._size;\r
452                 write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
453         }\r
454         HCL_heapstatLogWrite(gvar, heap_status, scratch);\r
455 \r
456         //far\r
457         strcpy(scratch,"\n      == far ==\n\n");\r
458         write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
459         fh_info._pentry = NULL;\r
460         fh_free=0; fh_total=0; fh_used=0;\r
461         for(;;) {\r
462                 heap_status = _fheapwalk( &fh_info );\r
463                 if( heap_status != _HEAPOK ) break;\r
464                 strcpy(scratch,"  "); strcat(scratch,(fh_info._useflag == _USEDENTRY ? "USED" : "FREE")); strcat(scratch," block at ");\r
465                 sprintf(str, "%Fp", fh_info._pentry); //ultoa((dword)fh_info._pentry,str,16);\r
466                         strcat(scratch,str); strcat(scratch," of size "); ultoa(fh_info._size,str,10); strcat(scratch,str); strcat(scratch,"\n");\r
467                 /*printf( "  %s block at %Fp of size %4.4X\n",\r
468 (fh_info._useflag == _USEDENTRY ? "USED" : "FREE"),\r
469 fh_info._pentry, fh_info._size );*/\r
470                 if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="FREE") fh_free += fh_info._size;\r
471                 if((fh_info._useflag == _USEDENTRY ? "USED" : "FREE")=="USED") fh_used += fh_info._size;\r
472                 fh_total += fh_info._size;\r
473                 write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
474         }\r
475         HCL_heapstatLogWrite(gvar, heap_status, scratch);\r
476 \r
477         strcpy(scratch,"\n");\r
478         strcat(scratch,kittengets(2,0,"Memory Type         Total      Used       Free\n"));\r
479         strcat(scratch,"----------------  --------   --------   --------\n");\r
480 //--    printmeminfoline(&scratch, "Default", h_total, h_used, h_free);\r
481         printmeminfoline(scratch, "Near", nh_total, nh_used, nh_free);\r
482         printmeminfoline(scratch, "Far", fh_total, fh_used, fh_free);\r
483         strcat(scratch,"----------------  --------   --------   --------\n");\r
484 #if defined(__LARGE__) || defined(__COMPACT__) || defined(__HUGE__)\r
485         strcat(scratch,"HC_coreleft = ");                       ultoa((dword)HC_coreleft(),str,10);                     strcat(scratch,str);    strcat(scratch,"\n");\r
486         strcat(scratch,"HC_farcoreleft = ");                    ultoa((dword)HC_farcoreleft(),str,10);          strcat(scratch,str);    strcat(scratch,"\n");\r
487 #endif\r
488 //--    strcat(scratch,"HC_Newfarcoreleft = ");         ultoa((dword)HC_Newfarcoreleft(),str,10);               strcat(scratch,str);    strcat(scratch,"\n");\r
489 //--    strcat(scratch,"HC_GetFreeSize = ");            ultoa((dword)HC_GetFreeSize(),str,10);          strcat(scratch,str);    strcat(scratch,"\n");\r
490 //00    strcat(scratch,"HC_GetNearFreeSize = ");        ultoa((dword)HC_GetNearFreeSize(),str,10);      strcat(scratch,str);    strcat(scratch,"\n");\r
491 //00    strcat(scratch,"HC_GetFarFreeSize = ");         ultoa((dword)HC_GetFarFreeSize(),str,10);       strcat(scratch,str);    strcat(scratch,"\n");\r
492         strcat(scratch,"coreleft = ");                          ultoa((dword)coreleft(),str,10);                                strcat(scratch,str);    strcat(scratch,"\n");\r
493         strcat(scratch,"farcoreleft = ");                       ultoa((dword)farcoreleft(),str,10);                     strcat(scratch,str);    strcat(scratch,"\n");\r
494         strcat(scratch,"stackavail = ");                        ultoa((dword)stackavail(),str,10);                      strcat(scratch,str);    strcat(scratch,"\n");\r
495         write(gvar->handle.heaphandle,scratch,strlen(scratch));\r
496         HC_CloseDebug(gvar);\r
497 }\r
498 \r
499 void HCL_heapstatLogWrite(global_game_variables_t *gvar, int heap_status, byte *str)\r
500 {\r
501         switch( heap_status ) {\r
502                 case _HEAPEND:\r
503                         strcpy((str),"OK - end of heap\n");\r
504                 break;\r
505                 case _HEAPEMPTY:\r
506                         strcpy((str),"OK - heap is empty\n");\r
507 \r
508                 break;\r
509                 case _HEAPBADBEGIN:\r
510                         strcpy((str),"ERROR - heap is damaged\n");\r
511                 break;\r
512 #ifdef __WATCOMC__\r
513                 case _HEAPBADPTR:\r
514                         strcpy((str),"ERROR - bad pointer to heap\n");\r
515                 break;\r
516 #endif\r
517                 case _HEAPBADNODE:\r
518                         strcpy((str),"ERROR - bad node in heap\n");\r
519         }\r
520         write(gvar->handle.heaphandle,(str),strlen((str)));\r
521 }\r
522 \r
523 void HCL_heapstat(int heap_status)\r
524 {\r
525         switch( heap_status ) {\r
526                 case _HEAPEND:\r
527                         //printf("OK - end of heap\n");\r
528                 break;\r
529                 case _HEAPEMPTY:\r
530                         //printf("OK - heap is empty\n");\r
531                 break;\r
532                 case _HEAPBADBEGIN:\r
533                         printf("ERROR - heap is damaged\n");\r
534                 break;\r
535 #ifdef __WATCOMC__\r
536                 case _HEAPBADPTR:\r
537                         printf("ERROR - bad pointer to heap\n");\r
538                 break;\r
539 #endif\r
540                 case _HEAPBADNODE:\r
541                         printf("ERROR - bad node in heap\n");\r
542         }\r
543 }\r
544 \r
545 //++\r
546 #ifdef __WATCOMC__\r
547 dword farcoreleft()\r
548 {\r
549 //----  _fheapgrow();\r
550 // #ifdef __BORLANDC__\r
551 //      return 0x90000UL-16UL;\r
552 // #endif\r
553 \r
554 #if !defined(__LARGE__) && !defined(__COMPACT__) && !defined(__HUGE__)\r
555 //----  return 0x90000UL+16UL;\r
556 //----  return 589824UL+16UL;\r
557 #else\r
558 //++++\r
559         return HC_farcoreleft();\r
560 //stack overflows       return HC_GetFarFreeSize();\r
561 #endif\r
562 }\r
563 \r
564 dword coreleft()\r
565 {\r
566         _nheapgrow();\r
567         return _memavl();\r
568 //      return HC_GetNearFreeSize();\r
569 }\r
570 #endif\r
571 \r
572 /*\r
573 ============================\r
574 =\r
575 = HC_OpenDebug / HC_CloseDebug\r
576 =\r
577 = Opens a binary file with the handle "heaphandle"\r
578 =\r
579 ============================\r
580 */\r
581 void HC_OpenDebug(global_game_variables_t *gvar)\r
582 {\r
583 #ifdef __BORLANDC__\r
584         unlink("heap.16b");\r
585         gvar->handle.heaphandle = open(gvar->handle.heapdumpfilename, O_CREAT | O_WRONLY | O_TEXT);\r
586 #endif\r
587 #ifdef __WATCOMC__\r
588         unlink("heap.16w");\r
589         gvar->handle.heaphandle = open(gvar->handle.heapdumpfilename, O_CREAT | O_WRONLY | O_TEXT);\r
590 #endif\r
591 }\r
592 \r
593 void HC_CloseDebug(global_game_variables_t *gvar)\r
594 {\r
595         close(gvar->handle.heaphandle);\r
596 \r
597 #ifdef __BORLANDC__\r
598         strcpy(gvar->handle.heapdumpfilename, "heap.16b");\r
599 #endif\r
600 #ifdef __WATCOMC__\r
601         strcpy(gvar->handle.heapdumpfilename, "heap.16w");\r
602 #endif\r
603 }\r