BeeJ
10/23/2011 11:57:00 PM
Jim Mack wrote :
>>
>> Yeah, so how would you implement that?
>> My string is a string of bytes, variable width. Each byte represents 8 bit
>> positions.
>> So for example, a string of 11 bytes represents 88 bits.
>> How do you use something else that is that compact?
>
> VB strings are not strings of bytes, they're BSTR -- strings of Unicode
> characters, which are 16 bits. Externally they may appear to be 8 bits but
> the transform is subject to distortion in certain ranges, which is why
> Thorsten cautioned about Chr$(). Plus, each string has a 32-bit size prefix,
> so your 88 bits becomes 208 bits of storage.
>
> Using long integers would give you (up to) 32 bits of data for each 32 bits
> of storage, and would not be subject to Unicode distortion.
>
> If you use arrays there will be additional storage overhead (the SAFEARRAY
> structure). Larger arrays minimize that impact. Whatever logic you're using
> to compute the character position within the string would work as well for
> long integer (or even byte) arrays, and should be much much faster than
> strings.
Wrong. They can be and are strings made of Bytes (or whatever you want
to call it). I have created them and disassembled them. No, 88 is
still 88 and I have code to prove that.
Give it a try.
Dim sStr as String
sStr = ChrB$(1) & ChrB$(2) & ChrB$(3)
' then do a
Debug.Print LenB(sStr)
' then
Dim aByte() as Byte
aByte = sStr
Debug.Print LBound(aByte), UBound(aByte)
Surprise.
etc.
And if anybody read what I have been working on they would remember:
1) I have only strings to work with. why would I want to create and
maintain a parallel array of anything else?
2) If nothing is selected the the string containing the BitField is =
"" taking up very little room indeed (just the usual String overhead)
but can be expanded to whatever BitField is needed without regard to
the limitations of Long (32 bits) etc. e.g. 253 (randomly chosen number
for illustrative purposes only)
3) In my case the most common situation is that the BitField having
contents is used on a small portion of the full array of strings which
comprise a Row,Column matrix.
Also, since this is a user interaction (mostly), the time to work the
Bit String stuff being measured at around 10uSec (10 microseconds) on
my old laptop seems fast enough to me. I doubt the user will notice
any difference between 10uSec and 1uSec. and when it is not a user
only operation, then it is a file copy or some other relatively long
interaction with the file system and is a very teeny tiny small
(technical term) percentage of what is happening.
This is just so much fun!