malloct / free pairing

Discuss PocketC for Palm OS (including Desktop Edition)

Postby wjl2 on Mon Mar 06, 2006 4:55 am

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
Posts: 2
Joined: Mon Feb 20, 2006 9:29 am
Location: USA

Postby dewey on Mon Mar 06, 2006 3:08 pm

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.
Site Admin
Posts: 749
Joined: Sun Oct 21, 2007 5:12 am

Postby wjl2 on Tue Mar 07, 2006 8:54 pm

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.
Posts: 2
Joined: Mon Feb 20, 2006 9:29 am
Location: USA

Return to PocketC for Palm OS

Who is online

Users browsing this forum: No registered users and 3 guests