[futurebasic] Re: [FB] malloc size question

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : December 2007 : Group Archive : Group : All Groups

From: Brian Stevens <bstevens33@...>
Date: Tue, 18 Dec 2007 14:53:51 -0700
On Dec 18, 2007, at 10:42 AM, Joe Lertola wrote:

> I tried this:
>
> dim as pointer p
> p = fn malloc( 1000 )
> print fn GetPtrSize(p)
>
> But I am getting zero as the answer.

That is because a pointer returned by Malloc is NOT the same as a  
pointer created with FN NewPtr. GetPtrSize will only work with  
pointers created with the TB NewPtr call.

To find the size of a malloc-created pointer, the code will need to  
call the malloc_size() function. In FB PPC code this will require  
glue code to branch to it. In FBtoC we should be able to call it  
directly (just like other calls that require glue in FB).  RP wrote  
sample code showing the glue. Could post if I find it. You also might  
want to read RP's informative post on malloc versus NewPtr versus  
NewHandle in OS X. If you can't find it I'll try and repost. Also,  
the Xcode docs have good information on all the related memory  
allocation calls.



Brian S.