• 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: NewPtr vs malloc
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NewPtr vs malloc


  • Subject: Re: NewPtr vs malloc
  • From: Brendan Younger <email@hidden>
  • Date: Sat, 8 Dec 2001 16:21:31 -0500

On Saturday, December 8, 2001, at 03:57 PM, Tomas Zahradnicky, Jr. wrote:

On Thursday, December 6, 2001, at 10:12 am, Joe Chang (l%l,m8) wrote:

Hi all,

I'm wondering if there are differences between NewPtr and malloc,
DisposePtr and free. Which ones are better? or just same?


They are both the same, i would use malloc vs NewPtr, since its more standard (exact same code will work everywhere)

Althrough they might seem the same, they are not. ptr = NewPtr(size) is mac os toolbox function which allocates free pointer block. You may want to allocate ptr = NewPtrClear(size) --- a cleared pointer block. You can get size of that block GetPtrSize(ptr) or tell user why the allocation failed err = MemError() right after a call to NewPtr. You may also resize the block using SetPtrSize and MemError afterwards.

However, all these have equivalents.
NewPtr = malloc
NewPtrClear = calloc
GetPtrSize = malloc_size
SetPtrSize = realloc
and MemError() is not needed as badly on a system with good virtual memory. If the pointer is nil, there is simply no memory to be had.
As far as actual implementation details, NewPtr currently calls malloc and DisposePtr calls free and I would assume the other functions did the same.

Brendan Younger


  • Follow-Ups:
    • Re: NewPtr vs malloc
      • From: "Tomas Zahradnicky, Jr." <email@hidden>
References: 
 >Re: NewPtr vs malloc (From: "Tomas Zahradnicky, Jr." <email@hidden>)

  • Prev by Date: Re: %* format doesn't work in NSLog
  • Next by Date: Re: NSBundle question
  • Previous by thread: Re: NewPtr vs malloc
  • Next by thread: Re: NewPtr vs malloc
  • Index(es):
    • Date
    • Thread