Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default String variables

I understand that a string variable size is 10 bytes + string length. Does
this mean that a a variable-length string which happens to have a length of 6
occupies the same amount of memory as a fixed-length string of the same size
(16 bytes), or does Excel assign a memory block capable of suiting a much
larger string when a variable-length string is declared?

I'm asking because I'm dealing with a macro that creates a string array
listing the types of products it has recorded data for, and it seems to be
occupying a surprising amount of processor time.
--
Burnnie Holliday
Data Wrangler
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default String variables

Okay... I don't really feel that was necessary to answer the question.

does:

Dim ThisVar as String
ThisVar = "ABCDEF"

take more memory than this:

Dim ThisVar as String * 6
ThisVar = "ABCDEF"

The entirety of the code in question is 221 lines long, and no, this is not
a direct excerpt. A direct excerpt isn't necessary to answer the question,
since the question is not about code, but how Excel handles variable
declaration.
--
Burnnie Holliday
Data Wrangler


"Don Guillett" wrote:

As ALWAYS , post your code for comments.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Burnnie Holliday" wrote in
message ...
I understand that a string variable size is 10 bytes + string length. Does
this mean that a a variable-length string which happens to have a length
of 6
occupies the same amount of memory as a fixed-length string of the same
size
(16 bytes), or does Excel assign a memory block capable of suiting a much
larger string when a variable-length string is declared?

I'm asking because I'm dealing with a macro that creates a string array
listing the types of products it has recorded data for, and it seems to be
occupying a surprising amount of processor time.
--
Burnnie Holliday
Data Wrangler


.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default String variables

See inline comments...


Okay... I don't really feel that was necessary to answer the question.


Well, if you had any reason at all for including the last paragraph in your
original posting, then you are wrong... your actual code is quite material
to helping with that part of your message.


does:

Dim ThisVar as String
ThisVar = "ABCDEF"

take more memory than this:

Dim ThisVar as String * 6
ThisVar = "ABCDEF"


If you really think you need to see an answer to the above question, here is
how Microsoft describes it a this link...

http://msdn.microsoft.com/en-us/library/dd942824.aspx

Declare String Data Intelligently
================================================== ======
Visual Basic allocates stack and heap memory differently according to the
type of strings you create. By understanding how this works, you can write
more efficient string code. String variables in procedures that are
non-static use space on the computer's stack. Use the following information
to write code that minimizes stack memory usage.

Local fixed-length strings less than or equal to 64 characters use 2 bytes
for each character in the string. They don't use heap memory.

Local fixed-length strings longer than 64 characters use 4 bytes of stack
memory for a pointer to the variable in heap memory and 2 bytes of heap
memory for each character in the string.Local variable-length strings use 4
bytes of stack memory for a pointer to the variable in heap memory, and a
variable amount of heap memory according to the length of the string.

If your code used a large number of fixed-length strings of 64 characters or
less, you can reduce stack usage by changing the strings to local
variable-length strings or making them static fixed-length strings.


The entirety of the code in question is 221 lines long, and no, this is
not
a direct excerpt. A direct excerpt isn't necessary to answer the
question,
since the question is not about code, but how Excel handles variable
declaration.


Again, I have to wonder why you went out of your way to include the last
paragraph in your original posting. Variable memory usage is not where long
processing time comes from... it comes directly from the method of coding
used to process the strings (no matter whether they are fixed or variable in
length).


--
Rick (MVP - Excel)

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Call Variables by String Thomas [PBD] Excel Programming 1 July 15th 08 02:10 PM
Call Variables by String Thomas [PBD] Excel Programming 0 July 15th 08 01:20 PM
String variables John New Users to Excel 3 July 16th 06 09:08 PM
Parse String into Variables Gary''s Student Excel Programming 3 September 21st 05 03:32 PM
String Variables [email protected] Excel Programming 1 August 30th 03 07:28 AM


All times are GMT +1. The time now is 10:43 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"