Re: How to efficiently allocate space for a variable length string in VB6?



interpasha@xxxxxxxxxxx wrote:
Hi, everyone!

I am working on a medium-size data acquisition project.
I need to allocate (10megabytes+) space for a variable-length string in
VB6 to store incoming data. Fixed-length string won't work as its 64kb
max.
The DLL for the hardware sensor that I am using, expects to find a
string with space already allocated for it.

What is the most efficient way to instantiate a large variable-length
string?
I thought I could use ReDim to allocate space, but I was not able to
figure out how to use it with a string.

As of now, I am using highly inefficient code such as:
Dim myString As String
Dim i As Long

myString = "AAAAA"
For i = 1 To 250000
myString = myString & "AAAAA"
Next i

I'd try the String function, this code ran without a problem on my VB6 win98 192MB system:

Private Sub Command1_Click()
Dim a As String
a = String(100000000, "A")
MsgBox "done"
End Sub

Mike
.



Relevant Pages

  • Re: Dynamic C String Problem
    ... Using the conio implementation i wanted to create a dynamic string, ... whereby its size would be determined after each keyboard hit; ... Of Course, I would prefer a standard portable code instead of conio, ... wouldn't be allocating 128 Bytes a waste to allocate such unnecessary ...
    (comp.lang.c)
  • Re: Dynamic C String Problem
    ... Using the conio implementation i wanted to create a dynamic string, ... whereby its size would be determined after each keyboard hit; ... Of Course i would prefer a standard portable code instead of conio, ... it be allocating 128 Bytes a waste to allocate such unnecessary memory ...
    (comp.lang.c)
  • Re: String to byte[] reloaded
    ... Indeed, most of them don't allocate, but relies on you to allocate. ... I am using .NET framework v1.1 and I need to compress my string. ... With a one million character string, there is no change in the pointer, and the AddrOfPinnedObject call still includes the correct offset. ... Probably small objects get moved to the Large Object Heap in order to pin them. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Returning a dynamic character array based on input length
    ... please note that you are *NOT* talking about an array. ... but that's not the usual Fortran idiom (and thus a lot of string ... can't read directly into the character variable in question because you ... afford to just statically allocate a temporary area that will for sure ...
    (comp.lang.fortran)
  • Re: String to byte[] reloaded
    ... Indeed, most of them don't allocate, but relies on you to allocate. ... I am using .NET framework v1.1 and I need to compress my string. ... Note that the Large Object Heap is a heap, ... I don't know why the offset isn't needed when you use a pinning pointer. ...
    (microsoft.public.dotnet.languages.csharp)