Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

dmalloc.h File Reference

Go to the source code of this file.


Defines

#define xmalloc(s)   debug_malloc_id((s),__FILE__,__LINE__)
#define xrealloc(p, s)   debug_realloc_id((p),(s),__FILE__,__LINE__)
#define xfree(p)   debug_free_id((p),__FILE__,__LINE__)
#define debug_malloc(s)   debug_malloc_id((s),__FILE__,__LINE__)
#define debug_realloc(p, s)   debug_realloc_id((p),(s),__FILE__,__LINE__)
#define debug_free(p)   debug_free_id((p),__FILE__,__LINE__)

Functions

void * debug_malloc_id (size_t, const char *, int)
void * debug_realloc_id (void *, size_t, const char *, int)
void debug_free_id (void *, const char *, int)
void * debug_realloc (void *, size_t)
void debug_free (void *)
void dmalloc_info (void *)
void dmalloc_report (void)
void dmalloc_verbose (const char *)

Variables

size_t dmalloc_live_memory

Define Documentation

#define debug_free p       debug_free_id((p),__FILE__,__LINE__)
 

Definition at line 20 of file dmalloc.h.

void * debug_malloc      debug_malloc_id((s),__FILE__,__LINE__)
 

Definition at line 18 of file dmalloc.h.

#define debug_realloc p,
     debug_realloc_id((p),(s),__FILE__,__LINE__)
 

Definition at line 19 of file dmalloc.h.

#define xfree p       debug_free_id((p),__FILE__,__LINE__)
 

Definition at line 17 of file dmalloc.h.

#define xmalloc      debug_malloc_id((s),__FILE__,__LINE__)
 

Definition at line 15 of file dmalloc.h.

#define xrealloc p,
     debug_realloc_id((p),(s),__FILE__,__LINE__)
 

Definition at line 16 of file dmalloc.h.


Function Documentation

void debug_free void *   
 

Definition at line 141 of file dmalloc.c.

References debug_free_id(), and p.

00142 {
00143   debug_free_id(p, "<UNKNOWN>", 0);
00144 }

void debug_free_id void *   ,
const char *   ,
int   
 

Definition at line 96 of file dmalloc.c.

References bnum, dmalloc_live_memory, event_number, bucket::file, file, free, bucket::line, NBUCK, bucket::next, p, bucket::size, and verbose_out.

Referenced by debug_free().

00097 {
00098   bucket *b_in = (bucket *)(((char *)p) - sizeof(bucket));
00099   bucket *b;
00100   bucket *prev;
00101   int chain_length = 0;
00102   int bnum = (((long)b_in) >> 4) % NBUCK;
00103   if (p == 0) return;
00104   
00105   for (b = buckets[bnum], prev = 0; b && b != b_in; prev = b, b = b->next)
00106     chain_length++;
00107   if (b == 0) {
00108     fprintf(stderr, "my_free given bad pointer %p\n", p);
00109     abort();
00110   }
00111   
00112   dmalloc_live_memory -= b->size;
00113   if (prev) prev->next = b->next;
00114   else buckets[bnum] = b->next;
00115   /* memset(p, 97, b->size); */
00116   if (verbose_out)
00117     fprintf(verbose_out, "%5d: %p +%-7d (%s:%d) -- %s:%d  %d\n", event_number,
00118             p, b->size, b->file, b->line, file, line, dmalloc_live_memory);
00119   event_number++;
00120   free(b_in);
00121 }

void* debug_malloc_id size_t   ,
const char *   ,
int   
 

Definition at line 20 of file dmalloc.c.

References bnum, dmalloc_live_memory, event_number, bucket::file, file, bucket::line, malloc, NBUCK, bucket::next, p, bucket::size, and verbose_out.

Referenced by debug_malloc(), and debug_realloc_id().

00021 {
00022   void *p = malloc(k + sizeof(bucket));
00023   bucket *b = (bucket *)p;
00024   int bnum = (((long)p) >> 4) % NBUCK;
00025   
00026   if (p == 0) {
00027     fprintf(stderr, "dmalloc:%s:%d: virtual memory exhausted (wanted %d)\n",
00028             file, line, k);
00029     abort();
00030   }
00031   
00032   b->size = k;
00033   b->next = buckets[bnum];
00034   b->file = file;
00035   b->line = line;
00036   buckets[bnum] = b;
00037   dmalloc_live_memory += k;
00038   p = (void *)(((char *)p) + sizeof(bucket));
00039   /* memset(p, 99, b->size); */
00040   if (verbose_out)
00041     fprintf(verbose_out, "%5d: %p +%-7d (%s:%d) ++  %d\n", event_number,
00042             p, b->size, file, line, dmalloc_live_memory);
00043   event_number++;
00044   return p;
00045 }

void* debug_realloc void *   ,
size_t   
 

Definition at line 135 of file dmalloc.c.

References debug_realloc_id(), and p.

00136 {
00137   return debug_realloc_id(p, k, "<UNKNOWN>", 0);
00138 }

void* debug_realloc_id void *   ,
size_t   ,
const char *   ,
int   
 

Definition at line 48 of file dmalloc.c.

References bnum, debug_malloc_id(), dmalloc_live_memory, event_number, bucket::file, file, bucket::line, NBUCK, bucket::next, p, realloc, bucket::size, and verbose_out.

Referenced by debug_realloc().

00049 {
00050   bucket *b_in = (bucket *)(((char *)p) - sizeof(bucket));
00051   bucket *b;
00052   bucket *prev;
00053   bucket *new_b;
00054   int bnum = (((long)b_in) >> 4) % NBUCK;
00055   if (p == 0) return debug_malloc_id(k, file, line);
00056   
00057   for (b = buckets[bnum], prev = 0; b && b != b_in; prev = b, b = b->next)
00058     ;
00059   if (b == 0) {
00060     fprintf(stderr, "debug_realloc given bad pointer %p\n", p);
00061     abort();
00062   }
00063   
00064   dmalloc_live_memory += k - b->size;
00065   if (verbose_out)
00066     fprintf(verbose_out, "%5d: %p +%-7d (%s:%d) >> ", event_number,
00067             p, b->size, b->file, b->line);
00068   
00069   new_b = (bucket *)realloc(b, k + sizeof(bucket));
00070   if (new_b == 0) {
00071     fprintf(stderr, "dmalloc:%s:%d: virtual memory exhausted (wanted %d)\n",
00072             file, line, k);
00073     abort();
00074   }
00075   
00076   new_b->size = k;
00077   if (new_b != b) {
00078     if (prev) prev->next = new_b->next;
00079     else buckets[bnum] = new_b->next;
00080     
00081     bnum = (((long)new_b) >> 4) % NBUCK;
00082     new_b->next = buckets[bnum];
00083     buckets[bnum] = new_b;
00084     
00085     p = (void *)(((char *)new_b) + sizeof(bucket));
00086   }
00087 
00088   if (verbose_out)
00089     fprintf(verbose_out, "%p +%-7d (%s:%d)\n", p, k, file, line);
00090   event_number++;
00091   return p;
00092 }

void dmalloc_info void *   
 

Definition at line 148 of file dmalloc.c.

References bnum, bucket::file, bucket::line, NBUCK, bucket::next, p, and bucket::size.

00149 {
00150   bucket *b_in = (bucket *)(((char *)p) - sizeof(bucket));
00151   bucket *b;
00152   int bnum = (((long)b_in) >> 4) % NBUCK;
00153   if (p == 0)
00154     fprintf(stderr, "dmalloc: 0x0\n");
00155   else {
00156     for (b = buckets[bnum]; b && b != b_in; b = b->next)
00157       ;
00158     if (b == 0) {
00159       fprintf(stderr, "dmalloc: %p: not my pointer\n", p);
00160     } else {
00161       fprintf(stderr, "dmalloc: %p +%-7d (%s:%d)\n",
00162               p, b->size, b->file, b->line);
00163     }
00164   }
00165 }

void dmalloc_report void   
 

Definition at line 169 of file dmalloc.c.

References dmalloc_live_memory, bucket::file, i, bucket::line, NBUCK, bucket::next, and bucket::size.

Referenced by main().

00170 {
00171   int i;
00172   bucket *b;
00173   fprintf(stderr, "dmalloc: %d bytes allocated\n", dmalloc_live_memory);
00174   for (i = 0; i < NBUCK; i++)
00175     for (b = buckets[i]; b; b = b->next)
00176       fprintf(stderr, "dmalloc: %p +%-7d (%s:%d)\n",
00177               (void *)(((char *)b) + sizeof(bucket)), b->size,
00178               b->file, b->line);
00179 }

void dmalloc_verbose const char *   
 

Definition at line 183 of file dmalloc.c.

References out_name(), and verbose_out.

Referenced by main().

00184 {
00185   if (out_name)
00186     verbose_out = fopen(out_name, "w");
00187   else
00188     verbose_out = stdout;
00189 }

Variable Documentation

size_t dmalloc_live_memory
 

Definition at line 13 of file dmalloc.h.

Referenced by debug_free_id(), debug_malloc_id(), debug_realloc_id(), and dmalloc_report().

 

Powered by Plone

This site conforms to the following standards: