Class

# MemoryBlock

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

A <span class="title-ref">MemoryBlock</span> object allocates a sequence of bytes in memory and manipulates those bytes directly. A <span class="title-ref">MemoryBlock</span> can be passed in place of a `Ptr</api/data_types/additional_types/ptr>` when used in a `Declare</api/language/declare>` call.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                     | Type                               | Read-Only | Shared |
|------------------------------------------|------------------------------------|-----------|--------|
| `LittleEndian<memoryblock.littleendian>` | `Boolean</api/data_types/boolean>` |           |        |
| `Size<memoryblock.size>`                 | `Integer</api/data_types/integer>` |           |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                              | Parameters                                                                                                                                                                                                                                | Returns                                           | Shared |
|---------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------|--------|
| `BooleanValue<memoryblock.booleanvalue>`          | offset As `Integer</api/data_types/integer>`                                                                                                                                                                                              | `Boolean</api/data_types/boolean>`                |        |
|                                                   | offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `Boolean</api/data_types/boolean>`                                                                                                                |                                                   |        |
| `Byte<memoryblock.byte>`                          | offset As `Integer</api/data_types/integer>`                                                                                                                                                                                              | `Integer</api/data_types/integer>`                |        |
|                                                   | offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `Integer</api/data_types/integer>`                                                                                                                |                                                   |        |
| `ColorValue<memoryblock.colorvalue>`              | offset As `Integer</api/data_types/integer>`, bits As `Integer</api/data_types/integer>`                                                                                                                                                  | `Color</api/data_types/color>`                    |        |
|                                                   | offset As `Integer</api/data_types/integer>`, bits As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `Color</api/data_types/color>`                                                                        |                                                   |        |
| `Compress<memoryBlock.compress>`                  | level As `CompressionLevels<memoryblock.compressionlevels>` = `MemoryBlock.CompressionLevels.Normal<memoryblock.compressionlevels>`                                                                                                       | MemoryBlock                                       |        |
| `Constructor<memoryblock.constructor0>`           | bytes As `Integer</api/data_types/integer>`                                                                                                                                                                                               |                                                   |        |
| `Constructor<memoryblock.constructor1>`           | data As `String</api/data_types/string>`                                                                                                                                                                                                  |                                                   |        |
| `CopyBytes<memoryblock.copybytes>`                | source As `MemoryBlock</api/language/memoryblock>`, offset As `Integer</api/data_types/integer>`, length As `Integer</api/data_types/integer>`, `Optional</api/language/optional>` targetOffset As `Integer</api/data_types/integer>` = 0 |                                                   |        |
| `CString<memoryblock.cstring>`                    | offset As `Integer</api/data_types/integer>`                                                                                                                                                                                              | `String</api/data_types/string>`                  |        |
|                                                   | offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `String</api/data_types/string>`                                                                                                                  |                                                   |        |
| `CurrencyValue<memoryblock.currencyvalue>`        | offset As `Integer</api/data_types/integer>`                                                                                                                                                                                              | `Currency</api/data_types/currency>`              |        |
|                                                   | offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `Currency</api/data_types/currency>`                                                                                                              |                                                   |        |
| `Decompress<memoryblock.decompress>`              |                                                                                                                                                                                                                                           | MemoryBlock                                       |        |
| `DoubleValue<memoryblock.doublevalue>`            | offset As `Integer</api/data_types/integer>`                                                                                                                                                                                              | `Double</api/data_types/double>`                  |        |
|                                                   | offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `Double</api/data_types/double>`                                                                                                                  |                                                   |        |
| `Int16Value<memoryblock.int16value>`              | offset As `Integer</api/data_types/integer>`                                                                                                                                                                                              | `Int16</api/data_types/additional_types/int16>`   |        |
|                                                   | offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `Int16</api/data_types/additional_types/int16>`                                                                                                   |                                                   |        |
| `Int32Value<memoryblock.int32value>`              | offset As `Integer</api/data_types/integer>`                                                                                                                                                                                              | `Int32</api/data_types/additional_types/int32>`   |        |
|                                                   | offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `Int32</api/data_types/additional_types/int32>`                                                                                                   |                                                   |        |
| `Int64Value<memoryblock.int64value>`              | offset As `Integer</api/data_types/integer>`                                                                                                                                                                                              | `Int64</api/data_types/additional_types/int64>`   |        |
|                                                   | offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `Int64</api/data_types/additional_types/int64>`                                                                                                   |                                                   |        |
| `Int8Value<memoryblock.int8value>`                | offset As `Integer</api/data_types/integer>`                                                                                                                                                                                              | `Int8</api/data_types/additional_types/int8>`     |        |
|                                                   | offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `Int8</api/data_types/additional_types/int8>`                                                                                                     |                                                   |        |
| `LeftB<memoryblock.leftb>`                        | bytes As `Integer</api/data_types/integer>`                                                                                                                                                                                               | MemoryBlock                                       |        |
| `Long<memoryblock.long>`                          | offset As `Integer</api/data_types/integer>`                                                                                                                                                                                              | `Integer</api/data_types/integer>`                |        |
|                                                   | offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `Integer</api/data_types/integer>`                                                                                                                |                                                   |        |
| `MidB<memoryblock.midb>`                          | offset As `Integer</api/data_types/integer>`                                                                                                                                                                                              | MemoryBlock                                       |        |
|                                                   | offset As `Integer</api/data_types/integer>`, length As `Integer</api/data_types/integer>`                                                                                                                                                | MemoryBlock                                       |        |
| `Operator_Add<memoryblock.operator_add>`          | value As MemoryBlock                                                                                                                                                                                                                      | MemoryBlock                                       |        |
| `Operator_Compare<memoryblock.operator_compare>`  | value As MemoryBlock                                                                                                                                                                                                                      | `Integer</api/data_types/integer>`                |        |
| `Operator_Convert<memoryblock.operator_convert0>` |                                                                                                                                                                                                                                           | `Ptr</api/data_types/additional_types/ptr>`       |        |
| `Operator_Convert<memoryblock.operator_convert1>` |                                                                                                                                                                                                                                           | `String</api/data_types/string>`                  |        |
| `Operator_Convert<memoryblock.operator_convert2>` | value As `Ptr</api/data_types/additional_types/ptr>`                                                                                                                                                                                      |                                                   |        |
| `Operator_Convert<memoryblock.operator_convert3>` | value As `String</api/data_types/string>`                                                                                                                                                                                                 |                                                   |        |
| `PString<memoryblock.pstring>`                    | offset As `Integer</api/data_types/integer>`                                                                                                                                                                                              | `String</api/data_types/string>`                  |        |
|                                                   | offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `String</api/data_types/string>`                                                                                                                  |                                                   |        |
| `Ptr<memoryblock.ptr>`                            | offset As `Integer</api/data_types/integer>`                                                                                                                                                                                              | MemoryBlock                                       |        |
|                                                   | offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As MemoryBlock                                                                                                                                       |                                                   |        |
| `RightB<memoryblock.rightb>`                      | bytes As `Integer</api/data_types/integer>`                                                                                                                                                                                               | MemoryBlock                                       |        |
| `SingleValue<memoryblock.singlevalue>`            | offset As `Integer</api/data_types/integer>`                                                                                                                                                                                              | `Double</api/data_types/double>`                  |        |
|                                                   | offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `Double</api/data_types/double>`                                                                                                                  |                                                   |        |
| `StringValue<memoryblock.stringvalue>`            | offset As `Integer</api/data_types/integer>`, length As `Integer</api/data_types/integer>`, encoding As `TextEncoding</api/text/encoding_text/textencoding>` = `Nil</api/language/nil>`                                                   | `String</api/data_types/string>`                  |        |
|                                                   | offset As `Integer</api/data_types/integer>`, length As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `String</api/data_types/string>`                                                                    |                                                   |        |
| `UInt16Value<memoryblock.uint16value>`            | offset As `Integer</api/data_types/integer>`                                                                                                                                                                                              | `UInt16</api/data_types/additional_types/uint16>` |        |
|                                                   | offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `UInt16</api/data_types/additional_types/uint16>`                                                                                                 |                                                   |        |
| `UInt32Value<memoryblock.uint32value>`            | offset As `Integer</api/data_types/integer>`                                                                                                                                                                                              | `UInt32</api/data_types/additional_types/uint32>` |        |
|                                                   | offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `UInt32</api/data_types/additional_types/uint32>`                                                                                                 |                                                   |        |
| `UInt64Value<memoryblock.uint64value>`            | offset As `Integer</api/data_types/integer>`                                                                                                                                                                                              | `UInt64</api/data_types/additional_types/uint64>` |        |
|                                                   | offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `UInt64</api/data_types/additional_types/uint64>`                                                                                                 |                                                   |        |
| `UInt8Value<memoryblock.uint8value>`              | offset As `Integer</api/data_types/integer>`                                                                                                                                                                                              | `UInt8</api/data_types/additional_types/uint8>`   |        |
|                                                   | offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `UInt8</api/data_types/additional_types/uint8>`                                                                                                   |                                                   |        |
| `WString<memoryblock.wstring>`                    | offset As `Integer</api/data_types/integer>`                                                                                                                                                                                              | `String</api/data_types/string>`                  |        |
|                                                   | offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `String</api/data_types/string>`                                                                                                                  |                                                   |        |

## Enumerations

<div id="memoryblock.compressionlevels">

<div class="rst-class">

forsearch

</div>

</div>

MemoryBlock.CompressionLevels

### CompressionLevels

> Specifies the type amount of compression to be used based upon the speed of the compression. This is used with the `Compress<memoryblock.compress>` method.
>
> | Enum   | Description                                                     |
> |--------|-----------------------------------------------------------------|
> | Normal | A medium level of compression which is also the default.        |
> | None   | No compression is applied.                                      |
> | Fast   | A small amount of compression but also the fastest as a result. |
> | Best   | The most compression possible which also takes the longest.     |

## Constants

> The following class constant is returned by Size when the size of the **MemoryBlock** cannot be determined.
>
> | Class Constant | Description                                       |
> |----------------|---------------------------------------------------|
> | SizeUnknown    | The size of the MemoryBlock cannot be determined. |

## Property descriptions

<div id="memoryblock.littleendian">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.LittleEndian

**LittleEndian** As `Boolean</api/data_types/boolean>`

> Sets the endianness of a <span class="title-ref">MemoryBlock</span>. The default is the endianness of the platform on which the code is being compiled.
>
> All current CPU targets (x86-32, x86-64, ARM-32, ARM-64) default to LittleEndian = `True</api/language/true>`.
>
> ``` xojo
> Var mb1 As New MemoryBlock(2) ' currently Little Endian = True on all platforms
> mb1.Int8Value(0) = 1
> mb1.Int8Value(1) = 2
>
> Var firstUInt16 As Int16
> firstUInt16 = mb1.UInt16Value(0)
> ' firstUInt16 = (256 * 2) + (1 * 1) = 513
>
> mb1.LittleEndian = False
> Var secondUInt16 As Int16
> secondUInt16 = mb1.UInt16Value(0)
> ' secondUInt16 = (256 * 1) + (1 * 2) = 258
> ```

<div id="memoryblock.size">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.Size

**Size** As `Integer</api/data_types/integer>`

> The size of the <span class="title-ref">MemoryBlock</span> in bytes.
>
> If you assign a value to this property, the <span class="title-ref">MemoryBlock</span> is resized, retaining as much of the existing data as possible.
>
> MemoryBlock has a class constant, SizeUnknown (`Integer</api/data_types/integer>`), whose value is -1. Size returns SizeUnknown when the <span class="title-ref">MemoryBlock</span> is of unknown size. You can get this condition with `Declare</api/language/declare>` statements. Also, `Ptr</api/data_types/additional_types/ptr>` returns a <span class="title-ref">MemoryBlock</span> with an unspecified, so it sets Size to -1; however, the <span class="title-ref">MemoryBlock</span> can still be used to access the data that is stored in the <span class="title-ref">MemoryBlock</span>.

## Method descriptions

<div id="memoryblock.booleanvalue">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.BooleanValue

**BooleanValue**(offset As `Integer</api/data_types/integer>`) As `Boolean</api/data_types/boolean>`

**BooleanValue**(offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `Boolean</api/data_types/boolean>`)

> Gets and sets boolean (True/False) values.
>
> 0 is `False</api/language/false>` while any non-zero value is `True</api/language/true>`. *offset* is in bytes from the beginning of the <span class="title-ref">MemoryBlock</span>.
>
> This example sets a byte in the <span class="title-ref">MemoryBlock</span> and then reads it.
>
> ``` xojo
> Var mm As New MemoryBlock(4)
> mm.BooleanValue(0) = True
>
> If mm.BooleanValue(0) Then
>   MessageBox("True")
> End If
> ```

<div id="memoryblock.byte">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.Byte

**Byte**(offset As `Integer</api/data_types/integer>`) As `Integer</api/data_types/integer>`

**Byte**(offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `Integer</api/data_types/integer>`)

> Gets or sets the passed byte value. Returns an `integer</api/data_types/integer>`. *offset* is in bytes from the beginning of the <span class="title-ref">MemoryBlock</span>.
>
> The following code stores character byte values in a <span class="title-ref">MemoryBlock</span> and displays it as a String:
>
> ``` xojo
> Var m As New MemoryBlock(12)
> m.Byte(0) = 72
> m.Byte(1) = 101
> m.Byte(2) = 108
> m.Byte(3) = 108
> m.Byte(4) = 111
> m.Byte(5) = 32
> m.Byte(6) = 87
> m.Byte(7) = 111
> m.Byte(8) = 114
> m.Byte(9) = 108
> m.Byte(10) = 100
> m.Byte(11) = 33
>
> Var hello As String = m.StringValue(0, m.Size) ' Hello World!
> ```

<div id="memoryblock.colorvalue">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.ColorValue

**ColorValue**(offset As `Integer</api/data_types/integer>`, bits As `Integer</api/data_types/integer>`) As `Color</api/data_types/color>`

**ColorValue**(offset As `Integer</api/data_types/integer>`, bits As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `Color</api/data_types/color>`)

> Gets or sets a `Color</api/data_types/color>` in one of three formats, selected by *bits*.
>
> *bits* can take on the following values:
>
> | Value | Description                                      |
> |-------|--------------------------------------------------|
> | 32    | 32-bit color (high byte unused)                  |
> | 24    | 24-bit color                                     |
> | 16    | 16-bit color (5 bits per color, high bit unused) |
>
> Returns a `Color</api/data_types/color>`. *offset* is in bytes from the beginning of the <span class="title-ref">MemoryBlock</span>.
>
> This example stores a color in a <span class="title-ref">MemoryBlock</span> and then accesses it.
>
> ``` xojo
> Var c As Color
> Var m As New MemoryBlock(4)
> m.ColorValue(0, 32) = &c43A245
>
> c = m.ColorValue(0, 32)
> ```

<div id="memoryblock.compress">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.Compress

**Compress**(level As `CompressionLevels<memoryblock.compressionlevels>` = `MemoryBlock.CompressionLevels.Normal<memoryblock.compressionlevels>`) As <span class="title-ref">MemoryBlock</span>

> Returns a compressed copy of the <span class="title-ref">MemoryBock</span> at the compression *level* passed.

<div id="memoryblock.constructor0">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.Constructor

**Constructor**(bytes as `Integer</api/data_types/integer>`)

> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> `Constructors</api/language/constructor>` are special methods called when you create an object with the `New</api/language/new>` keyword and pass in the parameters above.
>
> </div>
>
> Creates a new <span class="title-ref">MemoryBlock</span> with the size specified in *bytes*.
>
> For 32-bit apps, you can request a maximum of about 2 to 3 GB depending on the OS. Generally Windows is closer to 2GB and macOS/Linux are closer to 3GB. There is no practical limit for 64-bit apps.
>
> The following example reads a real number into a memory block and then displays it:
>
> ``` xojo
> Var m As New MemoryBlock(4)
> Var d As Single
> m.SingleValue(0) = 123.456
> d = m.SingleValue(0)
> MessageBox(d.ToString)
> ```
>
> The following example stores a string in a <span class="title-ref">MemoryBlock</span> and displays it:
>
> ``` xojo
> Var m As New MemoryBlock(13)
> m.Byte(0) = 12
> m.Byte(1) = 72
> m.Byte(2) = 101
> m.Byte(3) = 108
> m.Byte(4) = 108
> m.Byte(5) = 111
> m.Byte(6) = 32
> m.Byte(7) = 87
> m.Byte(8) = 111
> m.Byte(9) = 114
> m.Byte(10) = 108
> m.Byte(11) = 100
> m.Byte(12) = 33
> MessageBox(m.PString(0))
> ```

<div id="memoryblock.constructor1">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.Constructor

**Constructor**(data as `String</api/data_types/string>`)

> Creates a <span class="title-ref">MemoryBlock</span> from the data passed.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> This signature is supported for Android only.
>
> </div>

<div id="memoryblock.copybytes">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.CopyBytes

**CopyBytes**(source As `MemoryBlock</api/language/memoryblock>`, offset As `Integer</api/data_types/integer>`, length As `Integer</api/data_types/integer>`, `Optional</api/language/optional>` targetOffset As `Integer</api/data_types/integer>` = 0)

> Copies *length* bytes from the *source* <span class="title-ref">MemoryBlock</span> starting at *offset* to *targetOffset*.

<div id="memoryblock.cstring">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.CString

**CString**(offset As `Integer</api/data_types/integer>`) As `String</api/data_types/string>`

**CString**(offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `String</api/data_types/string>`)

> Returns a `String</api/data_types/string>`. *offset* is in bytes from the beginning of the <span class="title-ref">MemoryBlock</span>.
>
> A CString is a sequence of non-zero bytes followed by a terminating Chr(0) that marks the end of the CString. <span class="title-ref">MemoryBlock</span>.CString returns a `String</api/data_types/string>` consisting of the non-zero bytes beginning at *offset* and ending before the terminating 0 byte.
>
> When setting <span class="title-ref">MemoryBlock</span>.CString, one extra byte of space is needed for the CString terminator. Thus, for example, when setting the CString property of a <span class="title-ref">MemoryBlock</span> to a 15-byte string, 16 bytes of the <span class="title-ref">MemoryBlock</span> are actually set.
>
> ``` xojo
> Var m As New MemoryBlock(16)
> m.CString(0) = "Ecce quam bonum"
> ```
>
> This example shows how to add the terminating null if the string doesn't already have it. It uses the string that was constructed in the `Byte<memoryblock.byte>` example.
>
> ``` xojo
> Var m As New MemoryBlock(14)
> m.Byte(0) = 12 ' length byte for a PString
> m.Byte(1) = 72
> m.Byte(2) = 101
> m.Byte(3) = 108
> m.Byte(4) = 108
> m.Byte(5) = 111
> m.Byte(6) = 32
> m.Byte(7) = 87
> m.Byte(8) = 111
> m.Byte(9) = 114
> m.Byte(10) = 108
> m.Byte(11) = 100
> m.Byte(12) = 33
> MessageBox(m.PString(0))
>
> ' To read the string using CString, set the terminating byte before the call.
> m.Byte(13) = 0
> MessageBox(m.CString(1)) ' Skip first value which is the length for the String
> ```

<div id="memoryblock.currencyvalue">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.CurrencyValue

**CurrencyValue**(offset As `Integer</api/data_types/integer>`) As `Currency</api/data_types/currency>`

**CurrencyValue**(offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `Currency</api/data_types/currency>`)

> Gets or sets a `Currency</api/data_types/currency>` value. *Offset* is in bytes from the beginning of the <span class="title-ref">MemoryBlock</span>.
>
> This example sets a `Currency</api/data_types/currency>` value and then accesses it.
>
> ``` xojo
> Var c As Currency
> Var m As New MemoryBlock(8)
> m.CurrencyValue(0) = 34.54
> c = m.CurrencyValue(0)
> ```

<div id="memoryblock.decompress">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.Decompress

**Decompress** As <span class="title-ref">MemoryBlock</span>

> Returns a copy of the <span class="title-ref">MemoryBlock</span> with no compression applied.

<div id="memoryblock.doublevalue">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.DoubleValue

**DoubleValue**(offset As `Integer</api/data_types/integer>`) As `Double</api/data_types/double>`

**DoubleValue**(offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `Double</api/data_types/double>`)

> Gets or sets a `Double</api/data_types/double>` value. *Offset* is in bytes from the beginning of the <span class="title-ref">MemoryBlock</span>.
>
> This example sets a double value and then accesses it.
>
> ``` xojo
> Var d As Double
> Var m As New MemoryBlock(8)
> m.DoubleValue(0) = 3.14159265358979323846264338327950
>
> d = m.DoubleValue(0)
> ```

<div id="memoryblock.int16value">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.Int16Value

**Int16Value**(offset As `Integer</api/data_types/integer>`) As `Int16</api/data_types/additional_types/int16>`

**Int16Value**(offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `Int16</api/data_types/additional_types/int16>`)

> Gets or sets an `Int16</api/data_types/additional_types/int16>` value. *offset* is in bytes from the beginning of the <span class="title-ref">MemoryBlock</span>.
>
> This example sets an `Int16</api/data_types/additional_types/int16>` value and then accesses it.
>
> ``` xojo
> Var i As Int16
> Var m As New MemoryBlock(2)
> m.Int16Value(0) = 34
>
> i = m.Int16Value(0)
> ```

<div id="memoryblock.int32value">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.Int32Value

**Int32Value**(offset As `Integer</api/data_types/integer>`) As `Int32</api/data_types/additional_types/int32>`

**Int32Value**(offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `Int32</api/data_types/additional_types/int32>`)

> Gets or sets an `Int32</api/data_types/additional_types/int32>` value. *offset* is in bytes from the beginning of the <span class="title-ref">MemoryBlock</span>.
>
> This example sets a 32-bit integer and then accesses it.
>
> ``` xojo
> Var i As Int32
> Var m As New MemoryBlock(4)
> m.Int32Value(0) = 256495
>
> i = m.Int32Value(0)
> ```

<div id="memoryblock.int64value">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.Int64Value

**Int64Value**(offset As `Integer</api/data_types/integer>`) As `Int64</api/data_types/additional_types/int64>`

**Int64Value**(offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `Int64</api/data_types/additional_types/int64>`)

> Gets or sets an `Int64</api/data_types/additional_types/int64>` value. *offset* is in bytes from the beginning of the <span class="title-ref">MemoryBlock</span>.
>
> This example sets a 64-bit integer and then accesses it.
>
> ``` xojo
> Var i As Int64
> Var m As New MemoryBlock(8)
> m.Int64Value(0) = 256495900
>
> i = m.Int64Value(0)
> ```

<div id="memoryblock.int8value">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.Int8Value

**Int8Value**(offset As `Integer</api/data_types/integer>`) As `Int8</api/data_types/additional_types/int8>`

**Int8Value**(offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `Int8</api/data_types/additional_types/int8>`)

> Gets or sets an `Int8</api/data_types/additional_types/int8>` value. *offset* is in bytes from the beginning of the <span class="title-ref">MemoryBlock</span>.

<div id="memoryblock.leftb">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.LeftB

**LeftB**(bytes As `Integer</api/data_types/integer>`) As MemoryBlock

> Returns a new <span class="title-ref">MemoryBlock</span> of the specified size using the same endianness as the source <span class="title-ref">MemoryBlock</span>.
>
> This example uses LeftB to set the value of a new <span class="title-ref">MemoryBlock</span>.
>
> ``` xojo
> Var m As New MemoryBlock(8)
> m.Int64Value(0) = 256495900
>
> Var n As New MemoryBlock(8)
> n = m.LeftB(8)
> ```

<div id="memoryblock.long">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.Long

**Long**(offset As `Integer</api/data_types/integer>`) As `Integer</api/data_types/integer>`

**Long**(offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `Integer</api/data_types/integer>`)

> Gets or sets an `Integer</api/data_types/integer>`, four bytes in length. *offset* is in bytes from the beginning of the <span class="title-ref">MemoryBlock</span>.
>
> Equivalent to `Int32Value<memoryblock.int32value>`, which you should use instead.

<div id="memoryblock.midb">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.MidB

**MidB**(offset As `Integer</api/data_types/integer>`) As MemoryBlock

**MidB**(offset As `Integer</api/data_types/integer>`, length As `Integer</api/data_types/integer>`) As MemoryBlock

> Returns a new <span class="title-ref">MemoryBlock</span> of the specified size using the same endianness as the source <span class="title-ref">MemoryBlock</span>. *Offset* is in bytes from the beginning of the <span class="title-ref">MemoryBlock</span>.
>
> This example extracts two bytes from a <span class="title-ref">MemoryBlock</span>.
>
> ``` xojo
> Var m As New MemoryBlock(12)
> .
> .
> Var n As New MemoryBlock(4)
> n = m.MidB(1, 2)
> ```

<div id="memoryblock.operator_add">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.Operator_Add

**Operator_Add**(value As MemoryBlock) As MemoryBlock

> Overloads the `+</api/language/operators/mathematical/+>` operator for the <span class="title-ref">MemoryBlock</span> class, providing a way to add the passed <span class="title-ref">MemoryBlock</span> to the `Self</api/language/self_keyword>` instance. Returns the result as a <span class="title-ref">MemoryBlock</span>.

<div id="memoryblock.operator_compare">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.Operator_Compare

**Operator_Compare**(value As MemoryBlock) As `Integer</api/data_types/integer>`

> Defines the following comparison operators for the <span class="title-ref">MemoryBlock</span> class: =, `<</api/language/operators/comparison/less_than>`, \>, \<=, \>=, \<\>. It compares the passed <span class="title-ref">MemoryBlock</span> to the Self instance.
>
> Operator_Compare returns an `integer</api/data_types/integer>` whose meaning is as follows: \< 0 means that `Self</api/language/self_keyword>` is less than the passed parameter, 0 means that `Self</api/language/self_keyword>` is equal to the passed parameter, and \> 0 means that `Self</api/language/self_keyword>` is greater than the passed parameter.

<div id="memoryblock.operator_convert0">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.Operator_Convert

**Operator_Convert** As `Ptr</api/data_types/additional_types/ptr>`

> Converts a <span class="title-ref">MemoryBlock</span> to a `Ptr</api/data_types/additional_types/ptr>`.

<div id="memoryblock.operator_convert1">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

**Operator_Convert** As `String</api/data_types/string>`

> Converts a <span class="title-ref">MemoryBlock</span> to a `String</api/data_types/string>`.

<div id="memoryblock.operator_convert2">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

**Operator_Convert**(value As `Ptr</api/data_types/additional_types/ptr>`)

> Converts a `Ptr</api/data_types/additional_types/ptr>` to a <span class="title-ref">MemoryBlock</span>.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> This method is not supported for Android.
>
> </div>

<div id="memoryblock.operator_convert3">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

**Operator_Convert**(value As `String</api/data_types/string>`)

> Converts a `String</api/data_types/string>` to a <span class="title-ref">MemoryBlock</span>.

<div id="memoryblock.pstring">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.PString

**PString**(offset As `Integer</api/data_types/integer>`) As `String</api/data_types/string>`

**PString**(offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `String</api/data_types/string>`)

> Gets or sets a `String</api/data_types/string>`, up to 255 characters. The first byte is the length of the string. *offset* is in bytes from the beginning of the <span class="title-ref">MemoryBlock</span>.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> This method is not supported for Android.
>
> </div>
>
> The following example stores a string in a <span class="title-ref">MemoryBlock</span> and displays it:
>
> ``` xojo
> Var m As New MemoryBlock(13)
> m.Byte(0) = 12
> m.Byte(1) = 72
> m.Byte(2) = 101
> m.Byte(3) = 108
> m.Byte(4) = 108
> m.Byte(5) = 111
> m.Byte(6) = 32
> m.Byte(7) = 87
> m.Byte(8) = 111
> m.Byte(9) = 114
> m.Byte(10) = 108
> m.Byte(11) = 100
> m.Byte(12) = 33
> MessageBox(m.PString(0))
> ```

<div id="memoryblock.ptr">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.Ptr

**Ptr**(offset As `Integer</api/data_types/integer>`) As MemoryBlock

**Ptr**(offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As MemoryBlock)

> Gets or sets a <span class="title-ref">MemoryBlock</span> at the specified *offset*. *offset* is in bytes from the beginning of the <span class="title-ref">MemoryBlock</span>.
>
> If the <span class="title-ref">MemoryBlock</span>'s size is not known, then the <span class="title-ref">MemoryBlock</span> this returns will also have an unknown (-1) size, although it can still be used to access its data.
>
> MemoryBlocks automatically convert to `Ptr</api/data_types/additional_types/ptr>`.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> This method is not supported for Android.
>
> </div>
>
> This code converts a <span class="title-ref">MemoryBlock</span> to a `Ptr</api/data_types/additional_types/ptr>`:
>
> ``` xojo
> Var p As Ptr = mb
> ```
>
> This code retrieves another <span class="title-ref">MemoryBlock</span> (within the original <span class="title-ref">MemoryBlock</span>) at the specified offset and converts it to a `Ptr</api/data_types/additional_types/ptr>`:
>
> ``` xojo
> Var p As Ptr = mb.Ptr(n)
> ```
>
> This example stores a `Ptr</api/data_types/additional_types/ptr>` to a <span class="title-ref">MemoryBlock</span> property. If the <span class="title-ref">MemoryBlock</span> property goes out of scope, the `Ptr</api/data_types/additional_types/ptr>` will be invalid when retrieved.
>
> ``` xojo
> MBProperty = New MemoryBlock(8)
> MBProperty.StringValue(0, 8) = "a string"
>
> Var mb As New MemoryBlock(8)
> Var p As Ptr = MBProperty
> mb.Ptr(0) = p
> ```
>
> Because of implicit conversion between a `Ptr</api/data_types/additional_types/ptr>` and <span class="title-ref">MemoryBlock</span>, this can be shortened.
>
> ``` xojo
> Var mb As New MemoryBlock(8)
> mb.Ptr(0) = MBProperty
> ```
>
> This code will retrieve the <span class="title-ref">MemoryBlock</span> later.
>
> ``` xojo
> Var mb1 As MemoryBlock = mb.Ptr(0) ' Size will be unknown (-1)
> Var s As String = mb1.StringValue(0, 8)
> ```
>
> This code will store a `Ptr</api/data_types/additional_types/ptr>` to two methods.
>
> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> A pointer is 4 bytes on 32-bit targets and 8 bytes on 64-bit targets. The `MemoryBlock</api/language/memoryblock>` must be sized accordingly, and each subsequent pointer must be placed at an offset that reflects the pointer size of the target. Use the `Target32Bit</api/compiler_directives/target32bit>` and `Target64Bit</api/compiler_directives/target64bit>` compiler directives when writing code that must support both architectures.
>
> </div>
>
> ``` xojo
> Var mb As New MemoryBlock(16)
> mb.Ptr(0) = AddressOf someMethod
> mb.Ptr(8) = AddressOf someOtherMethod
> ```

<div id="memoryblock.rightb">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.RightB

**RightB**(bytes As `Integer</api/data_types/integer>`) As MemoryBlock

> Returns a new <span class="title-ref">MemoryBlock</span> of the specified size using the same endianness as the source <span class="title-ref">MemoryBlock</span>.
>
> This example uses RightB to set the value of a new <span class="title-ref">MemoryBlock</span>.
>
> ``` xojo
> Var m As New MemoryBlock(8)
> m.Int64Value(0) = 256495900
>
> Var n As New MemoryBlock(8)
> n = m.RightB(8)
> ```

<div id="memoryblock.singlevalue">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.SingleValue

**SingleValue**(offset As `Integer</api/data_types/integer>`) As `Double</api/data_types/double>`

**SingleValue**(offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `Double</api/data_types/double>`)

> Gets or sets a 4-byte representation of a single-precision floating number as a `Double</api/data_types/double>`. *offset* is in bytes from the beginning of the <span class="title-ref">MemoryBlock</span>.
>
> The following example sets a value in a <span class="title-ref">MemoryBlock</span> using `Single</api/data_types/single>` and then gets it.
>
> ``` xojo
> Var d As Double
> Var m As New MemoryBlock(8)
> m.SingleValue(0) = 256
>
> d = m.SingleValue(0)
> ```

<div id="memoryblock.stringvalue">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.StringValue

**StringValue**(offset As `Integer</api/data_types/integer>`, length As `Integer</api/data_types/integer>`, encoding As `TextEncoding</api/text/encoding_text/textencoding>` = `Nil</api/language/nil>`) As `String</api/data_types/string>`

**StringValue**(offset As `Integer</api/data_types/integer>`, length As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `String</api/data_types/string>`)

> Gets or sets a `String</api/data_types/string>` of arbitrary size; it may contain nulls, and is not prefixed with a length byte.
>
> When setting, if *length* is greater than the length of the string, it is padded with zeros. *offset* is in bytes from the beginning of the <span class="title-ref">MemoryBlock</span>.
>
> This example sets a string and then reads it back.
>
> ``` xojo
> Var s As String
> Var m As New MemoryBlock(8)
> m.StringValue(0, 2) = "Ha"
> s = m.StringValue(0, 2)
> ```

<div id="memoryblock.uint16value">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.UInt16Value

**UInt16Value**(offset As `Integer</api/data_types/integer>`) As `UInt16</api/data_types/additional_types/uint16>`

**UInt16Value**(offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `UInt16</api/data_types/additional_types/uint16>`)

> Gets or sets a `UInt16</api/data_types/additional_types/uint16>` value. *offset* is in bytes from the beginning of the <span class="title-ref">MemoryBlock</span>.
>
> This example sets a `UInt16</api/data_types/additional_types/uint16>` in a <span class="title-ref">MemoryBlock</span> and accesses it.
>
> ``` xojo
> Var i As UInt16
> Var m As New MemoryBlock(8)
> m.UInt16Value(0) = 15
>
> i = m.UInt16Value(0)
> ```

<div id="memoryblock.uint32value">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.UInt32Value

**UInt32Value**(offset As `Integer</api/data_types/integer>`) As `UInt32</api/data_types/additional_types/uint32>`

**UInt32Value**(offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `UInt32</api/data_types/additional_types/uint32>`)

> Gets or sets a `UInt32</api/data_types/additional_types/uint32>` value. *offset* is in bytes from the beginning of the <span class="title-ref">MemoryBlock</span>.
>
> This example sets a `UInt32</api/data_types/additional_types/uint32>` value in a <span class="title-ref">MemoryBlock</span> and then accesses it.
>
> ``` xojo
> Var i As UInt32
> Var m As New MemoryBlock(4)
> m.UInt32Value(0) = 48000
>
> i = m.UInt32Value(0)
> ```

<div id="memoryblock.uint64value">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.UInt64Value

**UInt64Value**(offset As `Integer</api/data_types/integer>`) As `UInt64</api/data_types/additional_types/uint64>`

**UInt64Value**(offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `UInt64</api/data_types/additional_types/uint64>`)

> Gets or sets a `UInt64</api/data_types/additional_types/uint64>` value. *offset* is in bytes from the beginning of the <span class="title-ref">MemoryBlock</span>.
>
> This example sets a `UInt64</api/data_types/additional_types/uint64>` in a <span class="title-ref">MemoryBlock</span> and then accesses it.
>
> ``` xojo
> Var i As UInt64
> Var m As New MemoryBlock(8)
> m.UInt64Value(0) = 48000
>
> i = m.UInt64Value(0)
> ```

<div id="memoryblock.uint8value">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.UInt8Value

**UInt8Value**(offset As `Integer</api/data_types/integer>`) As `UInt8</api/data_types/additional_types/uint8>`

**UInt8Value**(offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `UInt8</api/data_types/additional_types/uint8>`)

> Gets or sets a `UInt8</api/data_types/additional_types/uint8>` value. *offset* is in bytes from the beginning of the <span class="title-ref">MemoryBlock</span>.
>
> This example sets a `UInt8</api/data_types/additional_types/uint8>` to a <span class="title-ref">MemoryBlock</span> and then accesses it.
>
> ``` xojo
> Var i As UInt8
> Var m As New MemoryBlock(1)
> m.UInt8Value(0) = 6
>
> i = m.UInt8Value(0)
> ```

<div id="memoryblock.wstring">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

MemoryBlock.WString

**WString**(offset As `Integer</api/data_types/integer>`) As `String</api/data_types/string>`

**WString**(offset As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `String</api/data_types/string>`)

> Allows you to get or set null-terminated WStrings (UTF-16 strings) in a <span class="title-ref">MemoryBlock</span>. *offset* is in bytes from the beginning of the <span class="title-ref">MemoryBlock</span>. The `String</api/data_types/string>` returned by <span class="title-ref">MemoryBlock</span>.WString has encoding UTF-16.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> This method is not supported for Android.
>
> </div>

## Notes

MemoryBlocks can be used whenever you need a container for any arbitrary binary data.

MemoryBlocks are used when accessing entry points in shared libraries and when making OS calls using the `Declare</api/language/declare>` function.

MemoryBlocks supports creating a zero-length <span class="title-ref">MemoryBlock</span>.

For 32-bit apps, you can request a maximum of about 2 to 3 GB depending on the OS. Generally Windows is closer to 2GB and Mac/Linux are closer to 3GB. There is no practical limit for 64-bit apps.

The contents of a <span class="title-ref">MemoryBlock</span> can be viewed in the Debugger.

You can initialize a <span class="title-ref">MemoryBlock</span> from a string without using the constructor and declaring its size. For example, the following initializes a <span class="title-ref">MemoryBlock</span> from a `String</api/data_types/string>`.

``` xojo
Var s As String = "abcde"
Var mb As MemoryBlock
mb = s
MessageBox(mb.Size.ToString) ' displays 5
```

You can convert this <span class="title-ref">MemoryBlock</span> back to a `String</api/data_types/string>` with an assignment statement or a call that accepts a string. This statement converts the <span class="title-ref">MemoryBlock</span> back to a `String</api/data_types/string>`.

``` xojo
Var a As String
a = mb
```

You can also pass this <span class="title-ref">MemoryBlock</span> to a function that expects a `String</api/data_types/string>`. For example:

``` xojo
MessageBox(mb)  ' displays "abcde"
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### OutOfBoundsExceptions with StringValue

Accessing invalid StringValues can raise an `OutOfBoundsException</api/exceptions/outofboundsexception>`.

Accessing a MemoryBlock.StringValue with a size less than 0:

``` xojo
Var mb As New MemoryBlock(0)
Var s As String = mb.StringValue(5, -1) ' OutOfBounds because size < 0
```

You will also get an `OutOfBoundsException</api/exceptions/outofboundsexception>` if the StringValue length is less than 0.

## Sample code

The Faster String Appending with MemoryBlock project (included with Xojo in: Examples/Language/) uses MemoryBlocks to append two strings together as fast as possible. The main window has two `TextFields</api/user_interface/desktop/desktoptextfield>`, a `Button</api/user_interface/desktop/desktopbutton>`, and a `Label</api/user_interface/desktop/desktoplabel>` for displaying the result.

The user enters strings into the `TextFields</api/user_interface/desktop/desktoptextfield>` and clicks the `Button</api/user_interface/desktop/desktopbutton>`. The `Pressed` event for the `Button</api/user_interface/desktop/desktopbutton>` is the following:

``` xojo
Var m As MemBlockString

' create a New memBlockString
m = New MemBlockString

' add the strings into the memBlockString
m.AppendString(TextField1.Text)
m.AppendString(TextField2.Text)

' retreive the string
Label1.Text = m.GetString
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The MemBlockString object is a custom class. It has the properties:

- BufferSize As `Integer</api/data_types/integer>`
- Length As `Integer</api/data_types/integer>`
- mb As MemoryBlock
- TotalLength As `Integer</api/data_types/integer>`

The constructor is:

``` xojo
' This is a class to use a memoryBlock as a temporary buffer
' while creating long strings by appending to already existing
' strings.  It can be a lot quicker than s = s + "more text" if
' you have very long strings

' This is both the size of the original memoryBlock
' but also how much it increases by each time if needed
BufferSize = 100000 ' bigger than really needed

mb = New MemoryBlock(BufferSize)
TotalLength = BufferSize
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The appendString method is called in the `DesktopButton</api/user_interface/desktop/desktopbutton>`'s `Pressed` event:

``` xojo
Sub AppendString(s As String)
  #Pragma DisableBackgroundTasks

  Var l As Integer

  l = s.Length
  mb.StringValue(length, l) = s
  length = length + l

Exception 
  ' If we write beyond the end of the memoryBlock we need to replace it with a newer ' bigger one
  TotalLength = TotalLength + bufferSize
  mb.Size = TotalLength
  mb.StringValue(length, l) = s
  length = length + l
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Finally, the `Pressed` event handler calls getString to assign the appended string to the text property of the `DesktopLabel</api/user_interface/desktop/desktoplabel>`.

``` xojo
Sub GetString() As String
  #Pragma DisableBackgroundTasks
  Return mb.StringValue(0, length)
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The following example reads a real number into a memory block and then displays it:

``` xojo
Var m As New MemoryBlock(4)
Var d As Single
m.SingleValue(0) = 123.456
d = m.SingleValue(0)
MessageBox(d.ToString)
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The following example stores a string in a <span class="title-ref">MemoryBlock</span> and displays it:

``` xojo
Var m As New MemoryBlock(13)
m.Byte(0) = 12
m.Byte(1) = 72
m.Byte(2) = 101
m.Byte(3) = 108
m.Byte(4) = 108
m.Byte(5) = 111
m.Byte(6) = 32
m.Byte(7) = 87
m.Byte(8) = 111
m.Byte(9) = 114
m.Byte(10) = 108
m.Byte(11) = 100
m.Byte(12) = 33
MessageBox(m.PString(0))
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

To read the string using `CString</api/data_types/additional_types/cstring>`, add the terminating byte before the call, i.e.,

``` xojo
m.Byte(13) = 0
MessageBox(m.CString(1))
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

This example backs a `BinaryStream</api/files/binarystream>` with a <span class="title-ref">MemoryBlock</span> that is declared 0-sized:

``` xojo
Var mb As New MemoryBlock(0)
Var bs As New BinaryStream(mb)
bs.WriteInt32(4)
bs.WriteDouble(3.14)
bs.Close
MessageBox(mb.Long(0).ToString)
```

## Compatibility

|                       |     |
|-----------------------|-----|
| **Project Types**     | All |
| **Operating Systems** | All |

<div class="seealso">

`Object</api/data_types/additional_types/object>` parent class; `BinaryStream</api/files/binarystream>` class; `Declare</api/language/declare>` statement.

</div>
