a question on the overhead of Boehm-gc
Bostjan Vilfan <[email protected]>
| Newsgroups | gmane.comp.programming.garbage-collection.boehmgc |
|---|---|
| Message-ID | <CAAm34zo8tCzZY70AYLpBuExqt8p4SVfJQBdfYBjq3i8tS-B6dA@mail.gmail.com> |
Hello, I'm planning to use Boehm-gc in a project, and I have done some preliminary testing in the course of which I stumbled on a question that I don't know how to answer. I wonder if I can get some comments. Attached is a small C program that simply allocates memory in chunks of 5000 bytes, and after each 10 such allocations the used memory is printed out (heap size - free bytes). When used memory decreases, indicating garbage collection, that fact is noted. Now the question. According to the previous description each printout corresponds to an increase of used memory by 50000 bytes; however, the actual printout indicates an increase by more than 80000 bytes (the program was tested on Debian 7). This seems like a lot of overhead. Could someone, please, explain. Regards, bv _______________________________________________ Gc mailing list Gc-V9/[email protected] http://www.hpl.hp.com/hosted/linux/mail-archives/gc/
loop.c
(text/x-csrc, 1.9 KB)
#include "gc.h"
#include <assert.h>
#include <stdio.h>
/*
This program demonstrates the concept of garbage collection.
It consists of a simple loop, on each execution of which
10 blocks of memory of size 5000 are allocated and information
on used memory is obtained (size of heap minus free memory).
The amount of used memory is listed. When used memory decreases
from the old value (indicating that garbage collection had occurred),
the program pauses for user input.
*/
const int heapsize=1000000,chunk=5000,period=10;
const char false=0,true=1;
int i;
size_t oldmem=0;
char * memblock;
void Help() {
char ch;
printf("This program demonstrates the concept of garbage collection.\n");
printf("It consists of a simple loop, on each execution of which\n");
printf("10 blocks of memory of size 5000 are allocated and information\n");
printf("on used memory is obtained. The amount of used memory is listed.\n ");
printf("When used memory decreases from the old value (indicating that\n");
printf("garbage collection had occurred), the program pauses for user\n");
printf("input.\n");
printf("Press ENTER to continue.\n");
ch=getchar();
}
char Available() {
size_t busymem; char ch;
busymem=GC_get_heap_size()-GC_get_free_bytes();
if (oldmem>busymem) {
printf("Garbage collection! Continue (RETURN=yes/OTHER=no)\n");
ch=getchar();
if (ch=='\n') {
printf("%s %d %c","used mem: ",busymem,'\n');
oldmem=busymem; return true;
}
else {
printf("%s %d %c","used mem: ",busymem,'\n');
return false;
}
}
printf("%s %d %c","used mem: ",busymem,'\n');
oldmem=busymem;
return true;
}
void Allocate() {
memblock=GC_malloc(chunk);
}
int main()
{
GC_INIT(); /* Optional on Linux/X86; see below. */
GC_expand_hp(heapsize);
Help();
while (true) {
if (!Available()) break;
for (i=1;i<=period;i++) Allocate();
}
return 0;
}