1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
28 /* #define ENABLE_MEM_PROFILE */
29 /* #define ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS */
30 /* #define ENABLE_MEM_CHECK */
31 #define MEM_PROFILE_TABLE_SIZE 8192
34 * This library can check for some attempts to do illegal things to
35 * memory (ENABLE_MEM_CHECK), and can do profiling
36 * (ENABLE_MEM_PROFILE). Both features are implemented by storing
37 * words before the start of the memory chunk.
39 * The first, at offset -2*SIZEOF_LONG, is used only if
40 * ENABLE_MEM_CHECK is set, and stores 0 after the memory has been
41 * allocated and 1 when it has been freed. The second, at offset
42 * -SIZEOF_LONG, is used if either flag is set and stores the size of
45 * The MEM_CHECK flag is checked when memory is realloc'd and free'd,
46 * and it can be explicitly checked before using a block by calling
50 #if defined(ENABLE_MEM_PROFILE) && defined(ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS)
51 #define ENTER_MEM_CHUNK_ROUTINE() allocating_for_mem_chunk++
52 #define LEAVE_MEM_CHUNK_ROUTINE() allocating_for_mem_chunk--
54 #define ENTER_MEM_CHUNK_ROUTINE()
55 #define LEAVE_MEM_CHUNK_ROUTINE()
59 #define MAX_MEM_AREA 65536L
60 #define MEM_AREA_SIZE 4L
62 #if SIZEOF_VOID_P > SIZEOF_LONG
63 #define MEM_ALIGN SIZEOF_VOID_P
65 #define MEM_ALIGN SIZEOF_LONG
69 typedef struct _GFreeAtom GFreeAtom;
70 typedef struct _GMemArea GMemArea;
71 typedef struct _GRealMemChunk GRealMemChunk;
80 GMemArea *next; /* the next mem area */
81 GMemArea *prev; /* the previous mem area */
82 gulong index; /* the current index into the "mem" array */
83 gulong free; /* the number of free bytes in this mem area */
84 gulong allocated; /* the number of atoms allocated from this area */
85 gulong mark; /* is this mem area marked for deletion */
86 gchar mem[MEM_AREA_SIZE]; /* the mem array from which atoms get allocated
87 * the actual size of this array is determined by
88 * the mem chunk "area_size". ANSI says that it
89 * must be declared to be the maximum size it
90 * can possibly be (even though the actual size
97 gchar *name; /* name of this MemChunk...used for debugging output */
98 gint type; /* the type of MemChunk: ALLOC_ONLY or ALLOC_AND_FREE */
99 gint num_mem_areas; /* the number of memory areas */
100 gint num_marked_areas; /* the number of areas marked for deletion */
101 guint atom_size; /* the size of an atom */
102 gulong area_size; /* the size of a memory area */
103 GMemArea *mem_area; /* the current memory area */
104 GMemArea *mem_areas; /* a list of all the mem areas owned by this chunk */
105 GMemArea *free_mem_area; /* the free area...which is about to be destroyed */
106 GFreeAtom *free_atoms; /* the free atoms list */
107 GTree *mem_tree; /* tree of mem areas sorted by memory address */
108 GRealMemChunk *next; /* pointer to the next chunk */
109 GRealMemChunk *prev; /* pointer to the previous chunk */
113 static gulong g_mem_chunk_compute_size (gulong size);
114 static gint g_mem_chunk_area_compare (GMemArea *a,
116 static gint g_mem_chunk_area_search (GMemArea *a,
120 static GRealMemChunk *mem_chunks = NULL;
122 #ifdef ENABLE_MEM_PROFILE
123 static gulong allocations[MEM_PROFILE_TABLE_SIZE] = { 0 };
124 static gulong allocated_mem = 0;
125 static gulong freed_mem = 0;
126 static gint allocating_for_mem_chunk = 0;
127 #endif /* ENABLE_MEM_PROFILE */
133 g_malloc (gulong size)
138 #if defined(ENABLE_MEM_PROFILE) || defined(ENABLE_MEM_CHECK)
140 #endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
147 #if defined(ENABLE_MEM_PROFILE) || defined(ENABLE_MEM_CHECK)
149 #endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
151 #ifdef ENABLE_MEM_CHECK
153 #endif /* ENABLE_MEM_CHECK */
156 p = (gpointer) malloc (size);
158 g_error ("could not allocate %ld bytes", size);
161 #ifdef ENABLE_MEM_CHECK
165 p = ((guchar*) p + SIZEOF_LONG);
167 #endif /* ENABLE_MEM_CHECK */
169 #if defined(ENABLE_MEM_PROFILE) || defined(ENABLE_MEM_CHECK)
173 p = ((guchar*) p + SIZEOF_LONG);
176 #ifdef ENABLE_MEM_PROFILE
177 # ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS
178 if(!allocating_for_mem_chunk) {
180 if (size <= MEM_PROFILE_TABLE_SIZE - 1)
181 allocations[size-1] += 1;
183 allocations[MEM_PROFILE_TABLE_SIZE - 1] += 1;
184 allocated_mem += size;
185 # ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS
188 #endif /* ENABLE_MEM_PROFILE */
189 #endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
196 g_malloc0 (gulong size)
201 #if defined(ENABLE_MEM_PROFILE) || defined(ENABLE_MEM_CHECK)
203 #endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
210 #if defined (ENABLE_MEM_PROFILE) || defined (ENABLE_MEM_CHECK)
212 #endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
214 #ifdef ENABLE_MEM_CHECK
216 #endif /* ENABLE_MEM_CHECK */
219 p = (gpointer) calloc (size, 1);
221 g_error ("could not allocate %ld bytes", size);
224 #ifdef ENABLE_MEM_CHECK
228 p = ((guchar*) p + SIZEOF_LONG);
230 #endif /* ENABLE_MEM_CHECK */
232 #if defined(ENABLE_MEM_PROFILE) || defined(ENABLE_MEM_CHECK)
236 p = ((guchar*) p + SIZEOF_LONG);
239 # ifdef ENABLE_MEM_PROFILE
240 # ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS
241 if(!allocating_for_mem_chunk) {
243 if (size <= (MEM_PROFILE_TABLE_SIZE - 1))
244 allocations[size-1] += 1;
246 allocations[MEM_PROFILE_TABLE_SIZE - 1] += 1;
247 allocated_mem += size;
248 # ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS
251 # endif /* ENABLE_MEM_PROFILE */
252 #endif /* ENABLE_MEM_PROFILE */
259 g_realloc (gpointer mem,
264 #if defined(ENABLE_MEM_PROFILE) || defined(ENABLE_MEM_CHECK)
266 #endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
273 #if defined(ENABLE_MEM_PROFILE) || defined(ENABLE_MEM_CHECK)
275 #endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
277 #ifdef ENABLE_MEM_CHECK
279 #endif /* ENABLE_MEM_CHECK */
283 p = (gpointer) malloc (size);
286 #if defined(ENABLE_MEM_PROFILE) || defined(ENABLE_MEM_CHECK)
287 t = (gulong*) ((guchar*) mem - SIZEOF_LONG);
288 #ifdef ENABLE_MEM_PROFILE
290 #endif /* ENABLE_MEM_PROFILE */
292 #endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
294 #ifdef ENABLE_MEM_CHECK
295 t = (gulong*) ((guchar*) mem - SIZEOF_LONG);
297 g_warning ("trying to realloc freed memory\n");
299 #endif /* ENABLE_MEM_CHECK */
301 p = (gpointer) realloc (mem, size);
305 g_error ("could not reallocate %lu bytes", (gulong) size);
308 #ifdef ENABLE_MEM_CHECK
312 p = ((guchar*) p + SIZEOF_LONG);
314 #endif /* ENABLE_MEM_CHECK */
316 #if defined(ENABLE_MEM_PROFILE) || defined(ENABLE_MEM_CHECK)
320 p = ((guchar*) p + SIZEOF_LONG);
323 #ifdef ENABLE_MEM_PROFILE
324 #ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS
325 if(!allocating_for_mem_chunk) {
327 if (size <= (MEM_PROFILE_TABLE_SIZE - 1))
328 allocations[size-1] += 1;
330 allocations[MEM_PROFILE_TABLE_SIZE - 1] += 1;
331 allocated_mem += size;
332 #ifdef ENABLE_MEM_PROFILE_EXCLUDES_MEM_CHUNKS
335 #endif /* ENABLE_MEM_PROFILE */
336 #endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
343 g_free (gpointer mem)
347 #if defined(ENABLE_MEM_PROFILE) || defined(ENABLE_MEM_CHECK)
350 #endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
352 #if defined(ENABLE_MEM_PROFILE) || defined(ENABLE_MEM_CHECK)
353 t = (gulong*) ((guchar*) mem - SIZEOF_LONG);
355 #ifdef ENABLE_MEM_PROFILE
357 #endif /* ENABLE_MEM_PROFILE */
359 #endif /* ENABLE_MEM_PROFILE || ENABLE_MEM_CHECK */
361 #ifdef ENABLE_MEM_CHECK
362 t = (gulong*) ((guchar*) mem - SIZEOF_LONG);
364 g_warning ("freeing previously freed memory\n");
368 memset ((guchar*) mem + 8, 0, size);
369 #else /* ENABLE_MEM_CHECK */
371 #endif /* ENABLE_MEM_CHECK */
375 #endif /* ! USE_DMALLOC */
381 #ifdef ENABLE_MEM_PROFILE
384 for (i = 0; i < (MEM_PROFILE_TABLE_SIZE - 1); i++)
385 if (allocations[i] > 0)
386 g_log (g_log_domain_glib, G_LOG_LEVEL_INFO,
387 "%lu allocations of %d bytes\n", allocations[i], i + 1);
389 if (allocations[MEM_PROFILE_TABLE_SIZE - 1] > 0)
390 g_log (g_log_domain_glib, G_LOG_LEVEL_INFO,
391 "%lu allocations of greater than %d bytes\n",
392 allocations[MEM_PROFILE_TABLE_SIZE - 1], MEM_PROFILE_TABLE_SIZE - 1);
393 g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "%lu bytes allocated\n", allocated_mem);
394 g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "%lu bytes freed\n", freed_mem);
395 g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "%lu bytes in use\n", allocated_mem - freed_mem);
396 #endif /* ENABLE_MEM_PROFILE */
400 g_mem_check (gpointer mem)
402 #ifdef ENABLE_MEM_CHECK
405 t = (gulong*) ((guchar*) mem - SIZEOF_LONG - SIZEOF_LONG);
408 g_warning ("mem: 0x%08x has been freed %lu times\n", (gulong) mem, *t);
409 #endif /* ENABLE_MEM_CHECK */
413 g_mem_chunk_new (gchar *name,
418 GRealMemChunk *mem_chunk;
421 ENTER_MEM_CHUNK_ROUTINE();
423 mem_chunk = g_new (struct _GRealMemChunk, 1);
424 mem_chunk->name = name;
425 mem_chunk->type = type;
426 mem_chunk->num_mem_areas = 0;
427 mem_chunk->num_marked_areas = 0;
428 mem_chunk->mem_area = NULL;
429 mem_chunk->free_mem_area = NULL;
430 mem_chunk->free_atoms = NULL;
431 mem_chunk->mem_tree = NULL;
432 mem_chunk->mem_areas = NULL;
433 mem_chunk->atom_size = atom_size;
435 if (mem_chunk->type == G_ALLOC_AND_FREE)
436 mem_chunk->mem_tree = g_tree_new ((GCompareFunc) g_mem_chunk_area_compare);
438 if (mem_chunk->atom_size % MEM_ALIGN)
439 mem_chunk->atom_size += MEM_ALIGN - (mem_chunk->atom_size % MEM_ALIGN);
441 mem_chunk->area_size = area_size;
442 if (mem_chunk->area_size > MAX_MEM_AREA)
443 mem_chunk->area_size = MAX_MEM_AREA;
444 while (mem_chunk->area_size < mem_chunk->atom_size)
445 mem_chunk->area_size *= 2;
447 rarea_size = mem_chunk->area_size + sizeof (GMemArea) - MEM_AREA_SIZE;
448 rarea_size = g_mem_chunk_compute_size (rarea_size);
449 mem_chunk->area_size = rarea_size - (sizeof (GMemArea) - MEM_AREA_SIZE);
452 mem_chunk->area_size -= (sizeof (GMemArea) - MEM_AREA_SIZE);
453 if (mem_chunk->area_size < mem_chunk->atom_size)
455 mem_chunk->area_size = (mem_chunk->area_size + sizeof (GMemArea) - MEM_AREA_SIZE) * 2;
456 mem_chunk->area_size -= (sizeof (GMemArea) - MEM_AREA_SIZE);
459 if (mem_chunk->area_size % mem_chunk->atom_size)
460 mem_chunk->area_size += mem_chunk->atom_size - (mem_chunk->area_size % mem_chunk->atom_size);
463 mem_chunk->next = mem_chunks;
464 mem_chunk->prev = NULL;
466 mem_chunks->prev = mem_chunk;
467 mem_chunks = mem_chunk;
469 LEAVE_MEM_CHUNK_ROUTINE();
471 return ((GMemChunk*) mem_chunk);
475 g_mem_chunk_destroy (GMemChunk *mem_chunk)
477 GRealMemChunk *rmem_chunk;
481 g_assert (mem_chunk != NULL);
483 ENTER_MEM_CHUNK_ROUTINE();
485 rmem_chunk = (GRealMemChunk*) mem_chunk;
487 mem_areas = rmem_chunk->mem_areas;
490 temp_area = mem_areas;
491 mem_areas = mem_areas->next;
495 if (rmem_chunk->next)
496 rmem_chunk->next->prev = rmem_chunk->prev;
497 if (rmem_chunk->prev)
498 rmem_chunk->prev->next = rmem_chunk->next;
500 if (rmem_chunk == mem_chunks)
501 mem_chunks = mem_chunks->next;
503 if (rmem_chunk->type == G_ALLOC_AND_FREE)
504 g_tree_destroy (rmem_chunk->mem_tree);
508 LEAVE_MEM_CHUNK_ROUTINE();
512 g_mem_chunk_alloc (GMemChunk *mem_chunk)
514 GRealMemChunk *rmem_chunk;
518 ENTER_MEM_CHUNK_ROUTINE();
520 g_assert (mem_chunk != NULL);
522 rmem_chunk = (GRealMemChunk*) mem_chunk;
524 while (rmem_chunk->free_atoms)
526 /* Get the first piece of memory on the "free_atoms" list.
527 * We can go ahead and destroy the list node we used to keep
528 * track of it with and to update the "free_atoms" list to
529 * point to its next element.
531 mem = rmem_chunk->free_atoms;
532 rmem_chunk->free_atoms = rmem_chunk->free_atoms->next;
534 /* Determine which area this piece of memory is allocated from */
535 temp_area = g_tree_search (rmem_chunk->mem_tree,
536 (GSearchFunc) g_mem_chunk_area_search,
539 /* If the area has been marked, then it is being destroyed.
540 * (ie marked to be destroyed).
541 * We check to see if all of the segments on the free list that
542 * reference this area have been removed. This occurs when
543 * the ammount of free memory is less than the allocatable size.
544 * If the chunk should be freed, then we place it in the "free_mem_area".
545 * This is so we make sure not to free the mem area here and then
546 * allocate it again a few lines down.
547 * If we don't allocate a chunk a few lines down then the "free_mem_area"
549 * If there is already a "free_mem_area" then we'll just free this mem area.
553 /* Update the "free" memory available in that area */
554 temp_area->free += rmem_chunk->atom_size;
556 if (temp_area->free == rmem_chunk->area_size)
558 if (temp_area == rmem_chunk->mem_area)
559 rmem_chunk->mem_area = NULL;
561 if (rmem_chunk->free_mem_area)
563 rmem_chunk->num_mem_areas -= 1;
566 temp_area->next->prev = temp_area->prev;
568 temp_area->prev->next = temp_area->next;
569 if (temp_area == rmem_chunk->mem_areas)
570 rmem_chunk->mem_areas = rmem_chunk->mem_areas->next;
572 if (rmem_chunk->type == G_ALLOC_AND_FREE)
573 g_tree_remove (rmem_chunk->mem_tree, temp_area);
577 rmem_chunk->free_mem_area = temp_area;
579 rmem_chunk->num_marked_areas -= 1;
584 /* Update the number of allocated atoms count.
586 temp_area->allocated += 1;
588 /* The area wasn't marked...return the memory
594 /* If there isn't a current mem area or the current mem area is out of space
595 * then allocate a new mem area. We'll first check and see if we can use
596 * the "free_mem_area". Otherwise we'll just malloc the mem area.
598 if ((!rmem_chunk->mem_area) ||
599 ((rmem_chunk->mem_area->index + rmem_chunk->atom_size) > rmem_chunk->area_size))
601 if (rmem_chunk->free_mem_area)
603 rmem_chunk->mem_area = rmem_chunk->free_mem_area;
604 rmem_chunk->free_mem_area = NULL;
608 rmem_chunk->mem_area = (GMemArea*) g_malloc (sizeof (GMemArea) -
610 rmem_chunk->area_size);
612 rmem_chunk->num_mem_areas += 1;
613 rmem_chunk->mem_area->next = rmem_chunk->mem_areas;
614 rmem_chunk->mem_area->prev = NULL;
616 if (rmem_chunk->mem_areas)
617 rmem_chunk->mem_areas->prev = rmem_chunk->mem_area;
618 rmem_chunk->mem_areas = rmem_chunk->mem_area;
620 if (rmem_chunk->type == G_ALLOC_AND_FREE)
621 g_tree_insert (rmem_chunk->mem_tree, rmem_chunk->mem_area, rmem_chunk->mem_area);
624 rmem_chunk->mem_area->index = 0;
625 rmem_chunk->mem_area->free = rmem_chunk->area_size;
626 rmem_chunk->mem_area->allocated = 0;
627 rmem_chunk->mem_area->mark = 0;
630 /* Get the memory and modify the state variables appropriately.
632 mem = (gpointer) &rmem_chunk->mem_area->mem[rmem_chunk->mem_area->index];
633 rmem_chunk->mem_area->index += rmem_chunk->atom_size;
634 rmem_chunk->mem_area->free -= rmem_chunk->atom_size;
635 rmem_chunk->mem_area->allocated += 1;
639 LEAVE_MEM_CHUNK_ROUTINE();
645 g_mem_chunk_alloc0 (GMemChunk *mem_chunk)
649 mem = g_mem_chunk_alloc (mem_chunk);
652 GRealMemChunk *rmem_chunk = (GRealMemChunk*) mem_chunk;
654 memset (mem, 0, rmem_chunk->atom_size);
661 g_mem_chunk_free (GMemChunk *mem_chunk,
664 GRealMemChunk *rmem_chunk;
666 GFreeAtom *free_atom;
668 g_assert (mem_chunk != NULL);
669 g_assert (mem != NULL);
671 ENTER_MEM_CHUNK_ROUTINE();
673 rmem_chunk = (GRealMemChunk*) mem_chunk;
675 /* Don't do anything if this is an ALLOC_ONLY chunk
677 if (rmem_chunk->type == G_ALLOC_AND_FREE)
679 /* Place the memory on the "free_atoms" list
681 free_atom = (GFreeAtom*) mem;
682 free_atom->next = rmem_chunk->free_atoms;
683 rmem_chunk->free_atoms = free_atom;
685 temp_area = g_tree_search (rmem_chunk->mem_tree,
686 (GSearchFunc) g_mem_chunk_area_search,
689 temp_area->allocated -= 1;
691 if (temp_area->allocated == 0)
694 rmem_chunk->num_marked_areas += 1;
698 LEAVE_MEM_CHUNK_ROUTINE();
701 /* This doesn't free the free_area if there is one */
703 g_mem_chunk_clean (GMemChunk *mem_chunk)
705 GRealMemChunk *rmem_chunk;
707 GFreeAtom *prev_free_atom;
708 GFreeAtom *temp_free_atom;
711 g_assert (mem_chunk != NULL);
713 rmem_chunk = (GRealMemChunk*) mem_chunk;
715 if (rmem_chunk->type == G_ALLOC_AND_FREE)
717 prev_free_atom = NULL;
718 temp_free_atom = rmem_chunk->free_atoms;
720 while (temp_free_atom)
722 mem = (gpointer) temp_free_atom;
724 mem_area = g_tree_search (rmem_chunk->mem_tree,
725 (GSearchFunc) g_mem_chunk_area_search,
728 /* If this mem area is marked for destruction then delete the
729 * area and list node and decrement the free mem.
734 prev_free_atom->next = temp_free_atom->next;
736 rmem_chunk->free_atoms = temp_free_atom->next;
737 temp_free_atom = temp_free_atom->next;
739 mem_area->free += rmem_chunk->atom_size;
740 if (mem_area->free == rmem_chunk->area_size)
742 rmem_chunk->num_mem_areas -= 1;
743 rmem_chunk->num_marked_areas -= 1;
746 mem_area->next->prev = mem_area->prev;
748 mem_area->prev->next = mem_area->next;
749 if (mem_area == rmem_chunk->mem_areas)
750 rmem_chunk->mem_areas = rmem_chunk->mem_areas->next;
751 if (mem_area == rmem_chunk->mem_area)
752 rmem_chunk->mem_area = NULL;
754 if (rmem_chunk->type == G_ALLOC_AND_FREE)
755 g_tree_remove (rmem_chunk->mem_tree, mem_area);
761 prev_free_atom = temp_free_atom;
762 temp_free_atom = temp_free_atom->next;
769 g_mem_chunk_reset (GMemChunk *mem_chunk)
771 GRealMemChunk *rmem_chunk;
775 g_assert (mem_chunk != NULL);
777 rmem_chunk = (GRealMemChunk*) mem_chunk;
779 mem_areas = rmem_chunk->mem_areas;
780 rmem_chunk->num_mem_areas = 0;
781 rmem_chunk->mem_areas = NULL;
782 rmem_chunk->mem_area = NULL;
786 temp_area = mem_areas;
787 mem_areas = mem_areas->next;
791 rmem_chunk->free_atoms = NULL;
793 if (rmem_chunk->mem_tree)
794 g_tree_destroy (rmem_chunk->mem_tree);
795 rmem_chunk->mem_tree = g_tree_new ((GCompareFunc) g_mem_chunk_area_compare);
799 g_mem_chunk_print (GMemChunk *mem_chunk)
801 GRealMemChunk *rmem_chunk;
805 g_assert (mem_chunk != NULL);
807 rmem_chunk = (GRealMemChunk*) mem_chunk;
808 mem_areas = rmem_chunk->mem_areas;
813 mem += rmem_chunk->area_size - mem_areas->free;
814 mem_areas = mem_areas->next;
817 g_log (g_log_domain_glib, G_LOG_LEVEL_INFO,
818 "%s: %ld bytes using %d mem areas\n",
819 rmem_chunk->name, mem, rmem_chunk->num_mem_areas);
823 g_mem_chunk_info (void)
825 GRealMemChunk *mem_chunk;
829 mem_chunk = mem_chunks;
833 mem_chunk = mem_chunk->next;
836 g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "%d mem chunks\n", count);
838 mem_chunk = mem_chunks;
841 g_mem_chunk_print ((GMemChunk*) mem_chunk);
842 mem_chunk = mem_chunk->next;
849 GRealMemChunk *mem_chunk;
851 mem_chunk = mem_chunks;
854 g_mem_chunk_clean ((GMemChunk*) mem_chunk);
855 mem_chunk = mem_chunk->next;
861 g_mem_chunk_compute_size (gulong size)
867 while (power_of_2 < size)
870 lower = power_of_2 >> 1;
873 if ((size - lower) < (upper - size))
879 g_mem_chunk_area_compare (GMemArea *a,
882 return (a->mem - b->mem);
886 g_mem_chunk_area_search (GMemArea *a,
891 if (addr < &a->mem[a->index])