UserGuide

MemoryBlock

From Xojo Documentation

A MemoryBlock is used whenever you need a container for any arbitrary binary data.

A MemoryBlock object allocates a sequence of bytes in memory and manipulates those bytes directly. A MemoryBlock can be passed in place of a Ptr when used in a Declare call. For times when you need to directly manage a block of data in its raw (byte) form, you will need to use a MemoryBlock. When reviewing the API for creating Declare statements, you will find that some parameters require a pointer to a chuck of data. You can set up a memory block as the location for this data.

A MemoryBlock can be initialized with a String value. The byte contents of the string are assigned as the raw data for the MemoryBlock.

Dim s As String = "Hello!"
Dim mb As MemoryBlock
mb = s
MessageBox(mb.StringValue(0, mb.Size))

MemoryBlock can be used with Desktop, Web and Console projects but not with iOS projects.

iOS Notes

The iOS framework has two MemoryBlock classes: Xojo.Core.MemoryBlock, which is read-only, and Xojo.Core.MutableMemoryBlock, which can be modified. Since most MemoryBlocks are not modified after they are created using MemoryBlock in place of MutableMemoryBlock can result in better performance.

See Also

MemoryBlock, Xojo.Core.MemoryBlock, Xojo.Core.MutableMemoryBlock classes; UserGuide:Framework topic