From: Alexandros Peropulous on 1 Jul 2010 06:29 I have a huge decision tree, consisting of lots of parents and children. It's kind of a XML dom structure, but specialized with my own properties. It takes awfully long to build up at runtime. Is there any popular method of how to store such things in a single file so that I can "blit" it right into memory? :-) I guess not...
From: Alexandros Peropulous on 1 Jul 2010 07:25 If this is not possible I would also be glad to hear about how to blit let's say an array of this kind into memory: Dim myArr() as Single Redim myArr(10000,10000) I wonder if each value really has to be inserted "manually" when loading or if there is a faster method than this: For X = 1 to 100000 For Y = 1 to 100000 myArr(X, Y) = 'code to set value here...
From: Larry Serflaten on 1 Jul 2010 08:11 "Alexandros Peropulous" <peropero(a)gmail.com> wrote > If this is not possible I would also be glad to hear about how to blit > let's say an array of this kind into memory: > > Dim myArr() as Single > Redim myArr(10000,10000) > > I wonder if each value really has to be inserted "manually" when loading > or if there is a faster method than this: > > For X = 1 to 100000 > For Y = 1 to 100000 > myArr(X, Y) = 'code to set value here... To save the data to disk, open the file for Binary, and Put the array there: Put #file, , myArr Then to read it back, open it again for Binary and Get the data: Get #file, , myArr How's that for simplicity? If you can put your all of your tree into 'myArr', you're all set! LFS
From: Mike Williams on 1 Jul 2010 08:55 "Alexandros Peropulous" <peropero(a)gmail.com> wrote in message news:ug7ZaARGLHA.1868(a)TK2MSFTNGP05.phx.gbl... > I would also be glad to hear about how to blit let's say an array of this > kind into memory: > Dim myArr() as Single > Redim myArr(10000,10000) > I wonder if each value really has to be inserted > "manually" when loading or if there is a faster > method than this: For X = 1 to 10000 > For Y = 1 to 10000 . . . etc Actually unless you've used Option Base 1 in your code then the above would not be correct anyway, because the array elements would be 0 to 10000 (as opposed to 1 to 10000). But, to answer your question, you can easily pull the entire array in from disk in one go, although personally I would not be happy with creating arrays of such a size and would probably choose a different method that allowed you to have only so much data as your app is currently dealing with in memory at any one time . . or at least to split the data up into a number of smaller blocks if you really do need to have it all in memory at once (much depends on what else your code is doing and how much memory it is using for other things, but generally it is always much easier for the system to find ten blocks of 40 MB than it is for it to find one block of 400 MB). Anyway, one way of loading the data from file in one go is to use the Get statement, as in the following simple example. You can use a straight forward array (as in the example) or you can use a similar method to load a UDT in one go, which gives you more flexibility: Option Explicit Private myArr(1000, 1000) As Single Private Sub Command1_Click() ' save the data Open "c:\temp\test1.dta" For Binary As 1 Put #1, 1, myArray() Close 1 End Sub Private Sub Command2_Click() ' load the data Open "c:\temp\test1.dta" For Binary As 1 Get #1, 1, myArray() Close 1 End Sub Mike > myArr(X, Y) = 'code to set value here... >
From: Alexandros Peropulous on 1 Jul 2010 09:04 Okay, this works fine for singles and other standard types. How great. 2 questions: 1) I do have to know the array size and redim my array accordingly before loading it again, is that correct? 2) This does not work with objects. VB6 says that #Get and #Put do not support it... For example I can't put an array of user-defined types which point to a class. Would using an API function help or is that simply not possible, no matter what I do? Larry Serflaten: > "Alexandros Peropulous"<peropero(a)gmail.com> wrote >> If this is not possible I would also be glad to hear about how to blit >> let's say an array of this kind into memory: >> >> Dim myArr() as Single >> Redim myArr(10000,10000) >> >> I wonder if each value really has to be inserted "manually" when loading >> or if there is a faster method than this: >> >> For X = 1 to 100000 >> For Y = 1 to 100000 >> myArr(X, Y) = 'code to set value here... > > To save the data to disk, open the file for Binary, and Put the > array there: > > Put #file, , myArr > > Then to read it back, open it again for Binary and Get the data: > > Get #file, , myArr > > How's that for simplicity? > > If you can put your all of your tree into 'myArr', you're all set! > > LFS > >
|
Next
|
Last
Pages: 1 2 3 4 5 6 7 Prev: Developer friendly definition of TLB files Next: Permutation of an array |