Jym_Morton
(Jym Morton)
October 26, 2016, 6:13pm
1
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
Norman_P
(Norman P)
October 26, 2016, 6:17pm
2
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…
Norman_P
(Norman P)
October 26, 2016, 6:20pm
4
[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 )
Jym_Morton
(Jym Morton)
October 26, 2016, 6:55pm
7
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
Jym_Morton
(Jym Morton)
October 26, 2016, 7:07pm
9
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.