(Apply part of commit
db2b9f1 from 'racket_gc' branch.)
* include/gc.h (GC_get_memory_use): New API function declaration.
* misc.c (get_size, GC_get_memory_use): New function.
size_t /* stats_sz */);
#endif
+GC_API long GC_get_memory_use(void);
+
/* Disable garbage collection. Even GC_gcollect calls will be */
/* ineffective. */
GC_API void GC_CALL GC_disable(void);
}
#endif /* !NO_DEBUGGING */
+static void get_size(struct hblk *h, word lptr)
+{
+ hdr *hhdr = HDR(h);
+ long bytes = WORDS_TO_BYTES(hhdr->hb_sz);
+
+ bytes += HBLKSIZE-1;
+ bytes &= ~(HBLKSIZE-1);
+
+ *(long *)lptr += bytes;
+}
+long GC_get_memory_use()
+{
+ long c = 0;
+ LOCK();
+ GC_apply_to_all_blocks(get_size, (word)&c);
+ UNLOCK();
+ return c;
+}
+
/* Getter functions for the public Read-only variables. */
/* GC_get_gc_no() is unsynchronized and should be typically called */