Page 1 of 1

PostPosted: Mon Mar 06, 2006 4:55 am
by wjl2
Is it necessary to pair the malloct and free as in C, or are these more free heap allocations?

That is, if I do this:

pointer p,q, r;

p = malloct(1, "piics");
q = malloct(1, "picssi");
r = malloct(1, "piifs");


In C, this would either a mistake ('r' should have been freed first), or I'd have just freed the memory pointed to be 'q' *AND* 'r' and left that pointed to by 'p' active.

In Pocket C is the 'r' memory still allocated, or not?

If it is, has the 'q' memory actually been freed, or not?

- Bill

PostPosted: Mon Mar 06, 2006 3:08 pm
by dewey
This code is valid and safe in both C and PocketC - the order in which you free things is irrelevant. I have never heard of a dialect of C that has such horrible side effects in its free function.

PostPosted: Tue Mar 07, 2006 8:54 pm
by wjl2
Ach! Of course. I've been using a real-time in-house system for so long I'd forgotten that it's "free" wasn't normal. Thanks for the reminder.