Solved

Variable Length Strings -- Format of Extra 10 Bytes

Posted on 2002-04-24
7
180 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
[X]
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
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
Independent Software Vendors: 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!

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…

738 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