# MemoryBlock copying

If I’m copying 32 bytes from 1 MemoryBlock to another, do I use a loop or is there a quicker method?

mb is a large MemoryBlock
mb1 is MemoryBlock(32)

To copy from mb1 into mb where mb.Byte(50) is the start point.

For counter = 0 to 31
mb.Byte(50 + counter) = mb1.Byte(counter)
Next

Is this the most efficient way of doing it? I may have to do this 1000’s of times (50 will change by 32 each time it’s run)
TIA

look at memoryblock.stringvalue

why ? because STRINGS can be “a bunch of bytes” which is what you’re after for a memoryblock

As long as the 32 bytes don’t start at an arbitrary point, just treat the memoryblock as an array of UINT32 records.

mb1.UInt32Value(6) = mb.UInt32Value(6)
will copy the 7th block of 32 bytes from one to the other

edit:
hang on, thats bits…

[quote=294991:@Jeff Tullin]As long as the 32 bytes don’t start at an arbitrary point, just treat the memoryblock as an array of UINT32 records.

mb1.UInt32Value(6) = mb.UInt32Value(6)
will copy the 7th block of 32 bytes from one to the other[/quote]

this will copy 1 uint32 - or 8 bytes

what Norm said…

Use the stringvalue for longer lumps

So…

``dim mb1 as MemoryBlock = mb.StringValue( 50, 32 )``

So in the larger loop

```Dim i As Integer = mb.Size - 1 For LoopCount = 0 to i Step 32 dim mb1 as MemoryBlock(32) mb1 = myData.MidB(LoopCount, 32) Encrypt(mb1) mb.StringValue(Loopcount, 32) = mb1.StringValue(0, 32) //or is it mb1.MidB(0, 32) or just mb1 ? Next LoopCount```

{none of which cause an error in the IDE}

The classic MemoryBlock will convert transparently to String, so with a 32-byte MemoryBlock, these two blocks are identical:

``````dim s as string
s = mb.StringValue( 0, 32 )
s = mb``````

Likewise, if you are storing a MemoryBlock within another, you can just do this:

``mb.StringValue( 0 , 32 ) = mb1``

Darn I can’t have 2 people answer the question … If you’ve read this far, Norman and Kem combined to answer what turned into 2 questions.

No, it’s the byte count, not an index.