Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!usc!elroy.jpl.nasa.gov!ncar!news.miami.edu!umiami!gv9b2c9z From: gv9b2c9z@umiami.ir.miami.edu (Ordinary Man) Newsgroups: comp.sys.mac.programmer Subject: Re: Question About NewPtr... Message-ID: <1991Jan25.111038.7671@umiami.ir.miami.edu> Date: 25 Jan 91 16:10:37 GMT References: <1991Jan25.002913.7668@umiami.ir.miami.edu> Organization: Univ of Miami IR Lines: 47 In article <1991Jan25.002913.7668@umiami.ir.miami.edu>, ian@umiami.ir.miami.edu writes: > ...the information about NewPtr wasn't very specific...it says that NewPtr returns > a Ptr....I tried replacing all of my mallocs with NewPtr but now I get a > compile error saying that the varible and the Ptr returned by NewPtr aren't > the same...I'm not sure what I'm doing wrong...the varible I'm trying to set > is of type > SomeRecord *gAPointer; > could anyone help me out....Thanx > -- > Scruffy > Ian Sullivan Whenever you allocate memory with the memory manager routine NewPtr, it returns a generic pointer of type Ptr. If you wish to use this allocation in your program, and your pointer is of a different type than Ptr, you must typecast, and use that pointer instead. For example in PASCAL, you would say: type myData=whateverType; aPointer=^myData; var thisPtr:aPointer; begin .... thisPtr:=aPointer(NewPtr(sizeof(myData))); .... Now you can use this pointer anywhere you wish. But remeber that the memory manager routines expect the generic pointer as a parameter so you must say: .... DisposPtr(Ptr(thisPtr)); ... when you dispose of your pointer. Hope this helps, ==Dan -- /-------------------------------------------------------------------------\ | Dan Weisman - University of Miami - Florida | || || || || | |--------------------------------------------------| || || ||\ /|| | | INTERNET -----> gv9b2c9z@umiami.IR.Miami.edu | || || || | || | | BITNET -----> gv9b2c9z@umiami | ||||||| || | || | |-------------------------------------------------------------------------| | "...bows it's head and prays to the mother of all machines." | \_________________________________________________________________________/