malloc again

Discuss PocketC for CE (including Desktop Edition)

Postby joh.becker on Wed May 23, 2001 5:35 pm

I have checked a bit into the slow malloc problem.
As soon as you try to malloc memory after free'ing memory that is not the last allocated piece it gets dramatically slow. (Up to a factor 1000 slower)
This is only if the new block of memory fits into the free'd gap.
here some sample code:
int memtop = 0;
int time;

//------------------------------------------
my_malloc(int mem)
{
pointer p;

puts("malloc: ");
time = ticks();
p = malloc(mem);
time = ticks() - time;
memtop = p;
putsl(memtop+", "+mem+", ticks: "+time);
return(p);
}
//------------------------------------------
my_free(pointer p)
{
memtop = p;
free(p);
putsl("free: "+memtop);
}

//------------------------------------------
main()
{
pointer a, b, c, d, e, new_a;

graph_off();
putsl("start");
a = my_malloc(5000);
b = my_malloc(3000);
c = my_malloc(1000);
my_free(a);
new_a = my_malloc(2000);
d = my_malloc(1000);
e = my_malloc(3000);
my_free(new_a);
my_free(b);
my_free(c);
my_free(d);
my_free(e);
putsl("done");
}
joh.becker
 
Posts: 86
Joined: Tue Apr 17, 2001 6:51 am
Location: Germany

Return to PocketC for CE

Who is online

Users browsing this forum: No registered users and 2 guests

cron