Re: malloc in obj-c/cocoa
Re: malloc in obj-c/cocoa
- Subject: Re: malloc in obj-c/cocoa
- From: Ben Dougall <email@hidden>
- Date: Fri, 6 Feb 2004 23:02:47 +0000
On Friday, February 6, 2004, at 09:52 pm, Pete Yandell wrote:
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);
all make no difference - just the same :/
thanks.
_______________________________________________
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.