• 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: 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.

  • Follow-Ups:
    • Re: malloc in obj-c/cocoa
      • From: Ben Dougall <email@hidden>
References: 
 >malloc in obj-c/cocoa (From: Ben Dougall <email@hidden>)

  • Prev by Date: Re: malloc in obj-c/cocoa
  • Next by Date: RE: Are we still supposed to register Creator code (bundle signature) for OS X app?
  • Previous by thread: Re: malloc in obj-c/cocoa
  • Next by thread: Re: malloc in obj-c/cocoa
  • Index(es):
    • Date
    • Thread