• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: malloc in obj-c/cocoa
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Re: malloc in obj-c/cocoa (From: Pete Yandell <email@hidden>)

  • Prev by Date: Re: malloc in obj-c/cocoa
  • Next by Date: Re: malloc in obj-c/cocoa
  • Previous by thread: Re: malloc in obj-c/cocoa
  • Next by thread: Re: malloc in obj-c/cocoa
  • Index(es):
    • Date
    • Thread