[futurebasic] Re: [FB] Removing element from dynamic array

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : February 2006 : Group Archive : Group : All Groups

From: Alain Pastor <apastor@...>
Date: Sat, 25 Feb 2006 15:54:32 +0100
Bernie a écrit :
> 

> Nice one, Alain, that looks like (almost) the ultimate dynamic remove 
> function. I know it's an extra param but, what we really need is: 
> DynamiteRemoveItems( @dyn as pointer, firstItem as long, numberOfItems 
> as long ) plus another function: DynamiteInsertItems()
> 

local mode
local fn DynamicInsertItems( @dyn as ptr, startItem as long, numItems as 
long )
'~'1
dim as long      itemCount, itemSize
dim as pointer @ p

if ( dyn == _nil ) or ( startItem < 0 ) or ( numItems < 1 ) then exit fn
itemSize = ( fn malloc_size( dyn.AutoXREFPtr& ) \\ dyn.AutoXREFMax& )
if ( itemSize == 0 ) then exit fn
itemCount = dyn.autoXREFCurr&
p = fn realloc( dyn.AutoXREFPtr&, fn malloc_size( dyn.AutoXREFPtr& ) + ( 
numItems * itemSize ) )
if ( p = _nil ) then exit fn
dyn.AutoXREFPtr&  = p
dyn.AutoXREFHndl& = @dyn.AutoXREFPtr&
dyn.AutoXREFMax&  = itemCount + numItems
dyn.autoXREFCurr& = dyn.autoXREFCurr& + numItems
BlockMove(p + ( itemSize * startItem ), p + ( itemSize * (startItem + 
numItems) ), (itemCount - startItem) * itemSize )
BlockZero( p + ( itemSize * startItem ), numItems * itemSize )
end fn

Alain