Page 1 of 1

ReallocateMemory - only larger permitted?

Posted: Sat Jun 01, 2019 1:44 am
by juror
Minor change to the example to shorten the memory. Apparently, the old data is not retained?
I can shorten it using peekb and pokeb.
This post is for those who like me, hoped you could shorten a buffer using ReAllocateMemory.

Code: Select all

*Buffer = AllocateMemory(20)
  PokeS(*Buffer, 0, "12345678901234567")
  
  Debug "Buffer size: " + MemorySize(*Buffer)
  
  *NewBuffer = ReAllocateMemory(*Buffer, 18) ; need more memory
  If *NewBuffer
    Debug "New buffer size: " + MemorySize(*NewBuffer)
    
    Debug "The old content is still here:"
    For k = 0 To 17
      HexView$ + Hex(PeekB(*newbuffer, k), #PB_Byte) + " "
     Next
  Debug "Text encoded (hex view): " + HexView$
    
    FreeMemory(*NewBuffer) 
  EndIf