Re: malloc in obj-c/cocoa
Re: malloc in obj-c/cocoa
- Subject: Re: malloc in obj-c/cocoa
- From: Pete Yandell <email@hidden>
- Date: Sat, 7 Feb 2004 08:52:03 +1100
AFAIK you can mix malloc in with Objective-C code without any problems.
You've probably got other memory management issues going on.
On 07/02/2004, at 8:14 AM, Ben Dougall wrote:
PositionPtr posp;
posp = (PositionPtr) malloc( i ));
while( i >= 0 ) {
*(posp + i) = *(Buffer + i);
i--;
}
Apart from anything else that might be happening elsewhere in your
code, there's a problem right there. The memory you allocate runs from
posp to posp+i-1 and you go and write to posp+i. Try:
while (--i >= 0) *(posp + i) = *(Buffer + i);
or even:
while (--i >= 0) posp[i] = Bufffer[i];
or, if you're really clever:
memcpy (posp, Buffer, i);
Pete Yandell
http://pete.yandell.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.