ReAlloc

 (Available in 00 TS Tools(Base) - TS_Tools_PointerSafe)

Purpose

Change the size of the allocated memory

Syntax

IF !oPointerSafe:ReAlloc( oPointerSafe:ItemMax+100 )

Arguments

dwItemMax
DWORD

Description

Change the size of the allocated memory all previously allocated data is preserved. The method will return TRUE if it succeeded.

Note: This method will not decrease the amount of allocated memory.

Returns

TRUE if succeeded

Example

oPointerSafe:=TS_PointerSafe{ oOwner, 10, _SIZEOF( _WinGUID ) }
FOR X:=1 UPTO 100
   IF X>oPointerSafe:ItemMax
      IF !oPointerSafe:ReAlloc( oPointerSafe:ItemMax+10 )
         TSTrace Fatal "!oPointerSafe:ReAlloc(oPointerSafe:ItemMax+10)"
      END
   END
   pGUID:=oPointerSafe:ItemPointer( X )
// Do something with the GUID-pointer
   ... 
NEXT

Source

METHOD ReAlloc( dwItemMax AS DWORD ) AS LOGIC PASCAL CLASS TS_PointerSafe
LOCAL oPointerSafe AS TS_PointerSafe
LOCAL lRetVal AS LOGIC
   TSTrace Enter
   DO CASE
   CASE dwItemMax<=SELF:_ItemMax
      lRetVal:=TRUE
   CASE SELF:_BytesPointer==NULL_PTR .OR. SELF:_BytesAllocated ; ...
  ... ==0U
      TSTrace Warning "SELF:_BytesPointer==NULL_PTR .OR. SELF:_BytesAllocated==0U"
      lRetVal:=FALSE
   CASE SELF:IsValidObject
      oPointerSafe:=TS_PointerSafe{ SELF:Owner, dwItemMax, SELF:_ItemSize  ; ...
     ... }
      IF oPointerSafe:IsValidObject
         MemCopy( oPointerSafe:BytesPointer, SELF:_BytesPointer ; ...
        ... , Min( oPointerSafe:BytesAllocated, SELF:_BytesAllocated  ; ...
        ... ) )
         IF LOGIC( _CAST, MemFree( SELF:_BytesPointer ) )
            TSTrace Warning "LOGIC(_CAST,MemFree(SELF:_BytesPointer))"
         END
         SELF:_BytesAllocated:=oPointerSafe:BytesAllocated
         SELF:_BytesPointer:=oPointerSafe:BytesPointer
         SELF:_ItemMax:=oPointerSafe:ItemMax
         SELF:_ItemSize:=oPointerSafe:ItemSize
         SELF:_ItemCount:=Min( SELF:_ItemCount ; ...
        ... , SELF:_ItemMax )
         SELF:_ItemIndex:=Min( SELF:_ItemIndex ; ...
        ... , SELF:_ItemCount+1 )
         oPointerSafe:MemFree:=FALSE
         lRetVal:=TRUE
      ELSE
         TSTrace Warning "!oPointerSafe:IsValidObject"
         lRetVal:=FALSE
      END
      oPointerSafe:UnRegisterAxit( )
      oPointerSafe:Destroy( )
      oPointerSafe:=NULL_OBJECT
   OTHERWISE
      TSTrace Warning "!SELF:IsValidObject"
      lRetVal:=FALSE
   END
   TSTrace Leave
RETURN lRetVal