Solved

Variable Length Strings -- Format of Extra 10 Bytes

Posted on 2002-04-24
7
179 Views
Last Modified: 2010-05-02
When using variable length strings (which is a GOOD thing), what is the format for the extra 10 bytes that are used?
0
Comment
Question by:GivenRandy
  • 3
  • 2
  • 2
7 Comments
 
LVL 28

Accepted Solution

by:
AzraSound earned 50 total points
ID: 6966007
Is this what you are after?

http://www.vb2themax.com/HtmlDoc.asp?Table=Articles&ID=30

Gives description of internal storage of strings in memory
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6966192
Azra, that's interesting.  It appears that the second page has the relevant information.

Here's some string information:

Fixed-length strings are good if you know the exact size of the data to be saved, and will usually run much faster than a variable length string of th same size.

Variable length strings have a certain amount of overhead in order to know how much data is in the string.

A string constant may have a direct memory reference (in-line reference) or it may have an indirect memory reference (address pointer to where the string is found.)

--
Variable length string will usually have the indirect memory pointer, meaning that their structure usually consists of a few bytes indicating the length of the file, then an address indicating where the text is located.  To view the actual data, you need to follow the address and look for the specified number of bytes (maybe minus one.)

>what is the format for the extra 10 bytes
I haven't looked lately at the details, but hopefully the above is enough info for you.
0
 
LVL 9

Author Comment

by:GivenRandy
ID: 6967513
Not really sure if it answers it (I might have missed the answer in there). I figured there were about 4 bytes for length, 4 bytes for memory address, 2 for something else. Was looking for the layout of that. Was that in there?

I try to use variable-length strings unless absolutely required (but other options are usually better). VB.NET drops fixed-length strings.
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 28

Expert Comment

by:AzraSound
ID: 6967778
The figure on Page 2 seems to summarize it in its caption:

"The LenB function returns the value of the double word that immediately precedes the first character. The Dim x As String statement reserves 4 bytes for the descriptor, but no memory is allocated for the string until the first assignment occurs."

So, to me, that says:

8 bytes =
4 bytes for the double word telling length of string +
4 bytes for the descriptor
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6967779
I'm not sure where those other 2 bytes you are referring to are coming from.  Are you sure it is 10 bytes?
0
 
LVL 9

Author Comment

by:GivenRandy
ID: 6968268
For storage size, online help says "10 bytes + string length" for variable-length strings.
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6969107
I thought that a user-defined type might give me a clue:

Private Type x
  s As String
End Type

Private Sub Command2_Click()
  Dim y As x
  y.s = String$(65534, "q")
  Open "C:\qaz.txt" For Binary As #1
  Put #1, , y
  Close 1
End Sub

The output file contains a leading hex sequence of 2 bytes for strings less than 65535, and 6 bytes for strings of 65535 or more (64K - 1)

I suspect that the extra two bytes is used to differentiate between a "near pointer" and a "far pointer."
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question