[quote]Constructor(p As Ptr, size As UInteger)
The MemoryBlock does not take ownership of the memory, so the application is responsible for freeing it after the MemoryBlock has been destructed.[/quote]
How does one free a Xojo.Core.MemoryBlock?
I know how to free a “classic” MemoryBlock, as such one converts automatically to a Ptr, when used with
Declare Sub free Lib "libSystem.dylib" (p As Ptr)
But I don’t know how to get a pointer to a Xojo.Core.MemoryBlock.
Stupid me I have to free the pointer handed over to the MemoryBlock:
[code]Declare Sub free Lib “libSystem.dylib” (p As Ptr)
Dim p As Ptr = SomeFunctionReturningAPointer()
Dim mb As New Xojo.Core.MemoryBlock§
…
free§[/code]
I used to do free(mb) within the “classic” framework which worked because of the implicit conversion from MemoryBlock to Ptr.
I would create a subclass of MemoryBlock that calls free. That way you can never have a MemoryBlock that is pointing to invalid memory. I’d also pass in a size to the MemoryBlock’s constructor so that you can get bounds checking (if you do know the size).