/[guile]/guile/guile-core/libguile/gc-malloc.c
ViewVC logotype

Diff of /guile/guile-core/libguile/gc-malloc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.18 by hanwen, Wed May 14 11:01:23 2003 UTC revision 1.19 by hanwen, Sun Jul 6 14:54:07 2003 UTC
# Line 177  scm_strdup (const char *str) Line 177  scm_strdup (const char *str)
177    return scm_strndup (str, strlen (str));    return scm_strndup (str, strlen (str));
178  }  }
179    
180  void  
181  scm_gc_register_collectable_memory (void *mem, size_t size, const char *what)  static void
182    decrease_mtrigger (size_t size, const char * what)
183    {
184      scm_mallocated -= size;
185      scm_gc_malloc_collected += size;
186    }
187    
188    static void
189    increase_mtrigger (size_t size, const char *what)
190  {  {
191    if (ULONG_MAX - size < scm_mallocated)    if (ULONG_MAX - size < scm_mallocated)
192      {      {
# Line 188  scm_gc_register_collectable_memory (void Line 196  scm_gc_register_collectable_memory (void
196    scm_mallocated += size;    scm_mallocated += size;
197    
198    /*    /*
     we could finish the full sweep (without mark) here, but in  
     practice this turns out to be ineffective.  
    */  
   
   /*  
199      A program that uses a lot of malloced collectable memory (vectors,      A program that uses a lot of malloced collectable memory (vectors,
200      strings), will use a lot of memory off the cell-heap; it needs to      strings), will use a lot of memory off the cell-heap; it needs to
201      do GC more often (before cells are exhausted), otherwise swapping      do GC more often (before cells are exhausted), otherwise swapping
# Line 250  scm_gc_register_collectable_memory (void Line 253  scm_gc_register_collectable_memory (void
253                
254        scm_rec_mutex_unlock (&scm_i_sweep_mutex);        scm_rec_mutex_unlock (&scm_i_sweep_mutex);
255      }      }
256      }
257    
258    void
259    scm_gc_register_collectable_memory (void *mem, size_t size, const char *what)
260    {
261      increase_mtrigger (size, what);
262  #ifdef GUILE_DEBUG_MALLOC  #ifdef GUILE_DEBUG_MALLOC
263    if (mem)    if (mem)
264      scm_malloc_register (mem, what);      scm_malloc_register (mem, what);
265  #endif  #endif
266  }  }
267    
268    
269  void  void
270  scm_gc_unregister_collectable_memory (void *mem, size_t size, const char *what)  scm_gc_unregister_collectable_memory (void *mem, size_t size, const char *what)
271  {  {
272    scm_mallocated -= size;    decrease_mtrigger (size, what);
   scm_gc_malloc_collected += size;  
     
273  #ifdef GUILE_DEBUG_MALLOC  #ifdef GUILE_DEBUG_MALLOC
274    if (mem)    if (mem)
275      scm_malloc_unregister (mem);      scm_malloc_unregister (mem);
# Line 302  scm_gc_realloc (void *mem, size_t old_si Line 309  scm_gc_realloc (void *mem, size_t old_si
309  {  {
310    /* XXX - see scm_gc_malloc. */    /* XXX - see scm_gc_malloc. */
311    
312    
313      /*    
314      scm_realloc() may invalidate the block pointed to by WHERE, eg. by
315      unmapping it from memory or altering the contents.  Since
316      increase_mtrigger() might trigger a GC that would scan
317      MEM, it is crucial that this call precedes realloc().
318      */
319    
320      decrease_mtrigger (old_size, what);
321      increase_mtrigger (new_size, what);
322    
323    void *ptr = scm_realloc (mem, new_size);    void *ptr = scm_realloc (mem, new_size);
324    scm_gc_unregister_collectable_memory (mem, old_size, what);  
325    scm_gc_register_collectable_memory (ptr, new_size, what);  #ifdef GUILE_DEBUG_MALLOC
326      if (mem)
327        scm_malloc_reregister (mem, ptr, what);
328    #endif
329      
330    return ptr;    return ptr;
331  }  }
332    

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.19

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26