Results 1 to 4 of 4

Thread: [VB6] Bytarr - String-style operations by wrapping a Byte array

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    [VB6] Bytarr - String-style operations by wrapping a Byte array

    People seem to get tangled up in their underwear a lot trying to fiddle with binary data in String variables. Often they run into nightmares where they convert Unicode "to Unicode" and then back later, in the vain hope of avoiding data corruption. And then some locale boundary gets crossed and it all falls down. Hard.

    From what I've seen the bulk of this comes from the desire to use String operations on binary data. But most of these are fairly trivial to synthesize, especially with the help of CopyMemory.


    The Bytarr Class wraps a dynamic Byte array along with several properties and methods to make this easier.

    You can use the Class for lots of applications, or when you only need one or two operations it can server as a template for inline code when you don't want the Class.


    Bytarr (biter?) is bundled with a test program in the attachment. This also includes my Dump Class, which I find handy for debugging and testing.

    Name:  sshot.png
Views: 2945
Size:  8.0 KB


    There may be lingering bugs, but these should be easily found and fixed as required. You could also add more operations or convert the Class into a binary stringbuilder for better performance when you need to accumulate a lot of chunks into one array.
    Attached Files Attached Files
    Last edited by dilettante; Mar 5th, 2015 at 12:39 PM. Reason: reposted attachment with Clear() method enhanced

  2. #2
    Hyperactive Member
    Join Date
    Jun 2011
    Posts
    461

    Re: [VB6] Bytarr - String-style operations by wrapping a Byte array

    Is there any fast way to add one byte array to the beginning of another? I only see a "Cat" function which adds new bytes to the end of an array.
    All I can think of is to make some temporary array and store current array in it, then clear the current and add the array I want to be the first and after that add the temporary array to it, and when all is done release the temp. array from the memory.
    Last edited by MikiSoft; Apr 10th, 2015 at 04:17 PM.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [VB6] Bytarr - String-style operations by wrapping a Byte array

    Why not just create a new Bytarr, Cat the array you want first, then Cat the second one, and finally retrieve the Value?

    Or just write inline code to do the same thing if you don't need any of the other things that Bytarr provides? The main reason to use Bytarr is for those other operations.

    If you merely want to "glue" two Byte arrays together that's pretty trivial using CopyMemory. Just look at what the Cat method does.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [VB6] Bytarr - String-style operations by wrapping a Byte array

    If you want to hand-roll an "insert B at the front of A" you'd probably approach it just as you'd have to with a String. Make A larger (enough room for B) then slide the original contents of A "to the right" and insert B in front of that.

    This still requires 3 "copy" operations, since a Redim Preserve copies once, "sliding over" copies a second time, and "inserting" copies a 3rd time.

    If you create a temporary T with just Redim you have to copy B into T, then copy A into T, and finally copy T back to A. So you still copy 3 times.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width