Variable Length Strings -- Format of Extra 10 Bytes

Posted on 2002-04-24
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 50 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.
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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.
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…
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…
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

615 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