MemoryBlock.Uint64 returns Out of bounds with a valid offset in a small memory block

While trying to interprete some data I received in a DataGram I stumble on this weird issue:

I am trying to use the following function:

MemoryBlock.UInt64Value(Offset as Integer) As UInt64

The offset is in bytes according to the docs. However, when I try to access the data I quickly get an Out Of Bounds exception. The following code failed on the second assignment:

Dim ob as new MemoryBlock(8)
ob.Uint64Value(0) = 5250
ob.Uint64Value(4) = 5000

If I increase the MemoryBlock to 128 the it works and correctly load the value in the memory block at the correct offset.
Change the offset to a lower value than 4 like ob.Uint64Value(1), ob.Uint64Value(2) and so on fails in the same way.

Feels like a bug, but maybe I am not aware of certain limitations.

using 2019R3.1 running on MacOS Catalina 10.15.4

(In my use case I am actually reading data but used the write to find out what is going on)

a Uint64 is 8 bytes long… so your two values take up 16 bytes, your MB is only 8

An UInt64 is 8 bytes. If you start at index 4, you will overrun the MB by 4 bytes, so the error is correct. Either you really want UInt32 (4 bytes), or your MemoryBlock should be 16 bytes long and you would start the second index at 8.

Or what Dave just beat me to…

Dim ob as new MemoryBlock(8)
ob.Uint64Value(0) = 5250
ob.Uint64Value(4) = 5000

this looks like 2 Int32 or Uint32’s

OK, stupid me…

We’ve all been there.