-
Apr 11th, 2019, 07:10 AM
#1
Thread Starter
PowerPoster
-
Apr 11th, 2019, 07:16 AM
#2
Re: Quickly copy a huge string array to a UDT array
Can you provide some additional information?
What does your 2D UDT array looks like?
What kind of 2D string array do you have?
How big is a huge 2D string array?
-
Apr 11th, 2019, 07:20 AM
#3
Thread Starter
PowerPoster
Re: Quickly copy a huge string array to a UDT array
Hi Arnoutdv, I just deleted the attachment code and re-posted the new demo code.
-
Apr 11th, 2019, 03:47 PM
#4
Re: Quickly copy a huge string array to a UDT array
Dreammanor,
The way you've organized things, you've got it about as fast as it's going to get, safely.
One idea is to swap string pointers, thereby making the string array have an empty string, and the UDT's string having the actual string. However, that's not a copy. That's a swap. And, you'd have to be very careful that you did it correctly, or you'd get a crash.
If you actually want to copy the strings, and they're variable length, what you've got is about as good as it gets.
My first thought is just to organize your code such that the strings are read into the UDT in the first place. However, maybe that's not possible.
Now, if you could re-organize things and use fixed-length-strings, you could take advantage of some other things. For instance, if you re-organized your UDT such that each element within it was an array, rather than the whole thing being an array, and you made all the strings fixed length, then you could use CopyMemory to copy the whole block of strings.
Here's what I propose for your UDT:
Code:
Private Type Item_Info
Index() As Long
Key() As String
Text() As String * 20
End Type
Notice that each item is an array. Rather than have the whole UDT as an array, you'd Redim each element and just keep them the same number of dimensions.
Also notice that the string (Text) item is fixed length.
Then, you'd have to do the same to your string array:
Code:
Private m_arrText() As String * 20
Then, knowing the size of the arrays, you could use CopyMemory to copy all the string data in one-fell-swoop, very quick.
I didn't flesh out every detail, but the concepts are there. The whole idea is to get your strings such that they're in contiguous memory.
Good Luck,
Elroy
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Apr 12th, 2019, 01:35 AM
#5
Thread Starter
PowerPoster
Re: Quickly copy a huge string array to a UDT array
Hi Elroy, it's a good idea to use fixed-length strings or UDTs, which does improve performance. Thank you very much.
-
Apr 12th, 2019, 02:04 AM
#6
Fanatic Member
Re: Quickly copy a huge string array to a UDT array
Originally Posted by dreammanor
Hi Elroy, it's a good idea to use fixed-length strings or UDTs, which does improve performance. Thank you very much.
this guy is still working hard on his Spread Grid.
-
Apr 12th, 2019, 02:21 AM
#7
Thread Starter
PowerPoster
Re: Quickly copy a huge string array to a UDT array
Originally Posted by DaveDavis
this guy is still working hard on his Spread Grid.
You are very ignorant and full of malice. You may never get the Spread you want, and you will never understand what I'm doing.
Malicious speculation will never improve your programming skills.
-
Apr 12th, 2019, 03:53 AM
#8
Re: Quickly copy a huge string array to a UDT array
Hi,
why not use a Flat File with ADO ?
here my go with the Array -> to UDT
put this in a Modul
Code:
Option Explicit
Public Type SampleType
mName As String * 35
mField1 As String * 19
mField2 As String * 15
End Type
Public SampleData() As SampleType
and this in a Class
Code:
Option Explicit
Private Sample() As SampleType
Public Sub FillUDT(v As Variant)
'fill UDT
Dim i As Long
Dim s() As String
'Variant in Array
s() = v
'fill UDT from Array
ReDim Sample(UBound(s, 2))
For i = LBound(s, 2) To UBound(s, 2)
Sample(i).mName = s(0, i)
Sample(i).mField1 = s(1, i)
Sample(i).mField2 = s(2, i)
Next
End Sub
Public Sub PrintData(Column As Long)
Debug.Print "Class Sample-Column " & Column
Debug.Print Sample(Column).mName; Sample(Column).mField1; Sample(Column).mField2; vbCrLf;
' Debug.Print Sample(Column).mName
' Debug.Print Sample(Column).mField1
' Debug.Print Sample(Column).mField2
Debug.Print "------------------------------------------------------------------------------"
End Sub
and this in a Form
Code:
Option Explicit
'Ref. class
Private c1 As Class1
Private Sub Command1_Click()
Dim i As Long
For i = LBound(SampleData) To UBound(SampleData)
c1.PrintData i
Next
End Sub
Private Sub Form_Load()
Dim s() As String
Dim var As Variant
Dim i As Long
Set c1 = New Class1
'fill UDT
ReDim SampleData(1)
SampleData(0).mName = "Name1"
SampleData(0).mField1 = "Field1"
SampleData(0).mField2 = 111
SampleData(1).mName = "Name2"
SampleData(1).mField1 = "Field2"
SampleData(1).mField2 = 222
'UDT in Array
ReDim s(2, UBound(SampleData))
For i = LBound(SampleData) To UBound(SampleData)
s(0, i) = SampleData(i).mName
s(1, i) = SampleData(i).mField1
s(2, i) = SampleData(i).mField2
Next
'Array in Variant
var = s()
'Variant -> Class
c1.FillUDT var
End Sub
I didn't ckeck performance
hth
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
-
Apr 12th, 2019, 04:06 AM
#9
Fanatic Member
Re: Quickly copy a huge string array to a UDT array
Originally Posted by dreammanor
You are very ignorant and full of malice. You may never get the Spread you want, and you will never understand what I'm doing.
Malicious speculation will never improve your programming skills.
It is not Malicious speculation. People need to know what are you doing so that they can provide expertise to make your grid's Data
or specific case be manageable.
-
Apr 12th, 2019, 05:08 AM
#10
Thread Starter
PowerPoster
Re: Quickly copy a huge string array to a UDT array
Originally Posted by DaveDavis
It is not Malicious speculation. People need to know what are you doing so that they can provide expertise to make your grid's Data
or specific case be manageable.
If I'm wrong about you, I apologize to you.
I'm doing something that Microsoft is not willing to do, and these things will be of interest to all VB6ers. The difficulty and the workload of these things are so great that I don't know when I can finish it or whether I can continue to do it (because my work is often interrupted by other work), so I'll not disclose my plan for the time being. I think it would be more valuable to come up with a mature product that can be used directly in the future.
But one thing I can tell you is that it's not a difficult thing for me to develop a better Spread than FarpointSpread.
Last edited by dreammanor; Apr 12th, 2019 at 05:14 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|