Just starting out? Need help? Post your questions and find answers here.
juror
 
Posts: 5
Joined: Fri Aug 01, 2014 4:39 am

ReallocateMemory - only larger permitted?

by juror Sat Jun 01, 2019 1:44 am

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
Return to Coding Questions

Who is online

Users browsing this forum: No registered users and 4 guests