[futurebasic] Re: [FB] Disposing of a Pointer

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 2012 : Group Archive : Group : All Groups

From: Robert Purves <listrp@...>
Date: Thu, 12 Jan 2012 12:29:26 +1300
Waverly wrote:

> malloc_size
> I didn’t know this existed.  I’ve always worked around having to get the size whenever I use malloc.

malloc_size() may not give the answer you expect. malloc() likes to round up the request size, to a multiple of 16 or greater.

'-----
include "ConsoleWindow"
BeginCDeclaration
#include <malloc/malloc.h>
EndC
toolbox fn malloc_size( pointer ) = long


local fn Test( size as long )
dim as pointer  p, m

p = fn NewPtr( size )
m = fn malloc( size )
print fn GetPtrSize( p ), fn malloc_size( m )
DisposePtr( p )
free( m )
end fn

fn Test( 15 )
fn Test( 16 )
fn Test( 97 )
fn Test( 32769 )
'-----