Variable Length Strings -- Format of Extra 10 Bytes

Posted on 2002-04-24
Medium Priority
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?
Question by:GivenRandy
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
LVL 28

Accepted Solution

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


Gives description of internal storage of strings in memory
LVL 22

Expert Comment

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.

Author Comment

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.
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

LVL 28

Expert Comment

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
LVL 28

Expert Comment

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?

Author Comment

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

Expert Comment

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."

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

719 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