From: Alexandros Peropulous on
It took me quite a while to come back.

My current problem is that I have 2 classes:

-----------
Class "clsContainer"

Option Explicit

Private m() As clsField

Public Sub AddItem(ByVal uclsField As clsField)

Dim lUB&
lUB = UBound(m) + 1

ReDim Preserve m(0 To lUB)
Set m(lUB) = uclsField

End Sub
Public Property Get Count() As Long

Count = UBound(m)

End Property

Private Sub Class_Initialize()

ReDim m(0)

End Sub

Public Function CalculateAverage(ByVal uNumber As Long) As Long

Dim l&
For l = 1 To UBound(m)
Dim lVal&
lVal = m(l).CalculateAverage(uNumber)
(...)
Next l

(...)

End Function
------------
Class "clsIndex"

Option Explicit

Private m_lValueA&
private m_lValueB&

Public Sub ReadValues(ByVal uInput As String)

m_lValueA =ReadLeftFromChar(uInput, ":")
m_lValueB = ReadRightFromChar(uInput, ":")

End Sub
Public Property Get ValueA() As Long

ValueA = m_lValueA

End Property
Public Property Get ValueB() As Long

ValueA = m_lValueB

End Property

Public Function CalculateAverage(ByVal uNumber As Long) As Long

CalculateAverage = (m_lValueA + m_lValueB + uNumber) \ 3 (...)

End Function
----------------

And I fill LOTS of data into clsContainer this way (it takes over 5
minutes which is always driving me crazy):

Some Module

Private Sub FillContainer

Set m_Container = New clsContainer

dim l&
For l = 1 To LineReader.Count

Dim sValue$
sValue = LineReader.Item(l) 'This is a string of that kind: "9382:9372"

Dim nClsIndex As clsIndex
Set nClsIndex = New clsIndex
Call nClsIndex.ReadValues(sValue)

Call m_Container.AddItem(nClsIndex)

Next l

End Sub
-------------------
I was hoping that I could serialize nClsContainer instead of rewriting
my code. My code is currently for debugging and testing, and this
clsContainer is used a lot in other places of my code.

Could I get some thoughts about my problem and the horrible call to load
the values into the class?
From: Alexandros Peropulous on
Asking differently:
Looking at the huge memory consumption in my program I wonder if my way
of coding is just bad.
My coding is built on classes, as you can see from my last post.
But this is a performance killer, and simply unloading my program takes
around 3 minutes.
I think with collections or arrays of UDTs I could be more efficient.
I once stopped working with UDTs because I got error of that
cannot-bla-bla-user defined type in private modules" or similar. I guess
you all know these error messages.
If I remember correctly, they were thrown when I tried to do something
like this:
Public Function DoThis(byref nMyUDT as MyUDT). That's why I started
using classes.
How do you all do this?
From: Larry Serflaten on

"Alexandros Peropulous" <peropero(a)gmail.com> wrote
> It took me quite a while to come back.
>
> My current problem is that I have 2 classes:
> -----------
> Class "clsContainer"
>
> Private m() As clsField
>
> Public Sub AddItem(ByVal uclsField As clsField)
>
> Dim lUB&
> lUB = UBound(m) + 1
>
> ReDim Preserve m(0 To lUB)
> Set m(lUB) = uclsField
>
> End Sub
......
> Class "clsIndex"
>
> Private m_lValueA&
> private m_lValueB&

> ----------------
>
> And I fill LOTS of data into clsContainer this way (it takes over 5
> minutes which is always driving me crazy):

I see 3 classes, the clsContainer, a clsfield, and clsindex.

If the purpose of clsIndex is to hold 2 values, I would suggest you
drop that class. Scalar values are better held in an array than in a
class.

And finally, it is always prudent to reduce the number of times you
use ReDim Preserve. Consider: (air code, for example only)

Option Explicit
Private mMax as long
Private mLast as Long

Private mFields() as clsField

Private Sub Initialize()
mMax = 4096
mLast = -1
ReDim mFields(0 to mMax)
End Sub

Public Sub AddItem(pField as clsField)
mLast = mLast + 1
If mLast > mMax then
mMax = mMax + 4096
ReDim Preserve mFields(0 to mMax)
End If
Set mFields(mLast) = pField
End If


Notice how the number of elements are bumped up 4K at a time. That
reduces the number of ReDims to 1 time for every 4K times you had
before. I just picked 4K as a suitable number for the situation. You
can (as others may) use whatever value seems appropreate for the
situation, the more the merrier. Some multiply mMax by 2 each time,
but for large arrays that may leave a significant amount of wasted space.
You decide what is an appropreate bump value for your situation depending
on how many elements you expect to end up with.

But again, if the fields are simple scalar values, you may do much better
by storing them in an array. For which your container would be:

ReDim mContainer(0 To 1, 0 To mMax) As Long

And all the read , store, and average routines would be in a .bas module....

LFS



From: Alexandros Peropulous on
Thanks for the information.
From: Schmidt on

"Alexandros Peropulous" <peropero(a)gmail.com> schrieb im Newsbeitrag
news:OcTYdq1LLHA.5776(a)TK2MSFTNGP06.phx.gbl...
> Asking differently:
> Looking at the huge memory consumption in my program I wonder if my way
> of coding is just bad.
> My coding is built on classes, as you can see from my last post.
> But this is a performance killer, and simply unloading my program takes
> around 3 minutes.

Using up to - let's say - 100000 class-instances is
"yet OK" in a VB6-App.

Above that, you should switch to UDT-based Arrays.


> I once stopped working with UDTs because I got error of that
> cannot-bla-bla-user defined type in private modules" or similar.
> I guess you all know these error messages.
> If I remember correctly, they were thrown when I tried to do
> something like this:
> Public Function DoThis(byref nMyUDT as MyUDT). That's
> why I started using classes.

Try using the Friend-Keyword instead:
Friend Function DoThis(byref nMyUDT as MyUDT)

Olaf