Thread

Very Puzzling Function (Sdk)

Very Puzzling Function // Sdk

1  2  |  

brant

May 24, 2002, 2:08pm
As part of the "sekrit project," I've been putting together hard-to-write
functions while I wait for MrGrimm (a.k.a. 9 9 9) to finish the VB version
of the new SDK. One of the most difficult parts of the project is being
able to determine whether there are any objects in a cell that encroach into
the cell. To explain this better, imagine that there is a single
walk001h.rwx filling an entire cell that needs to be built. This function
is supposed to determine whether there are any other objects either in the
cell or overlapping into the cell that would cause the walk001h.rwx to be in
a state of encroachment.

While other parts of the project have been relatively simple, I've been
working on this part for four days straight and have yet to find an
acceptable solution. Yesterday night, I finally got the function to work
correctly, but unfortunately, it can take up to two seconds(!) for each
call. If 30 people are in AWTeen at a time and if just 8 of them perform
the action that requires this function to be called two times per minute,
the bot will be grinding away computing encroachment values for half the
time! The problem is that it has to search through all of the AWObjects in
a large collection that contains a 5X5 query result. I can reduce the load
to deal with 3X3 queries only, but the wait is still ridiculously long.
Someone suggested to me to implement a binary search, but doing so wouldn't
help because it would be impossible to sort the objects in such a manner as
to eliminate some of them, because some are obviously larger than others and
some can be very large (i.e. that blue wall section that takes up five
cells). The nested For loops are killing the processor, but I can't see any
ways to eliminate them.

The function is below. Any help anyone could provide in improving the speed
on this one would be much appreciated.

--------------
'CitNum is the number of the owner of the objects that should be ignored
(i.e. the builder)
Public Function CheckCellForEncroachment(ByRef AWObjectsCol As AWObjects,
CellX As Long, CellZ As Long, CitNum As Long)
Dim TempX As Long, TempZ As Long, XCounter As Long, ZCounter As Long
Dim XCheck As Boolean
Dim ZCheck As Boolean
'AWObj is an object representing an AW object - X here is the X
coordinate, Z is the Z coordinate
For Each AWObj In AWObjectsCol
If AWObj.Owner <> CitNum Then
'This part takes care of the case when the object is actually in
the cell
If AWObj.X >= CellX And AWObj.X <= CellX + 1000 And AWObj.Z >=
CellZ And AWObj.Z <= CellZ + 1000 Then
CheckCellForEncroachment = True
Exit Function
End If
TempX = mCol(AWObj.Model).X
TempZ = mCol(AWObj.Model).Z
XCheck = False
ZCheck = False
'for loops are necessary in the case that an object fills more
than two cells
'in this case, an object could acutally encroach by having both
ends out of the cell
'in question, while the middle is in the building
For XCounter = TempX To 0 Step -1000
For ZCounter = TempZ To 0 Step -1000
'coordinates of objects in negative numbered cells are
LOWER than the cell coordinate,
'while the coordinates of objects in positive numbered
cells are HIGHER than the coordinate
'this, either the slow abs() function must be used, or
an if else clause is needed
If AWObj.X > 0 Then
If (AWObj.X - TempX > CellX And AWObj.X - TempX <=
CellX + 1000) Or (AWObj.X + TempX > CellX And AWObj.X + TempX <= CellX +
1000) Then
XCheck = True
End If
Else
If (AWObj.X - TempX < CellX And AWObj.X - TempX >=
CellX - 1000) Or (AWObj.X + TempX < CellX And AWObj.X + TempX >= CellX -
1000) Then
XCheck = True
End If
End If
If AWObj.Z > 0 Then
If (AWObj.Z - TempZ > CellZ And AWObj.Z - TempZ <=
CellZ + 1000) Or (AWObj.Z + TempZ > CellZ And AWObj.Z + TempZ <= CellZ +
1000) Then
ZCheck = True
End If
Else
If (AWObj.Z - TempZ < CellZ And AWObj.Z - TempZ >=
CellZ + 1000) Or (AWObj.Z + TempZ < CellZ And AWObj.Z + TempZ >= CellZ -
1000) Then
ZCheck = True
End If
End If
If XCheck And ZCheck Then
CheckCellForEncroachment = True
Exit Function
End If
Next
Next
End If
Next
CheckCellForEncroachment = False
'if no object is found that encroaches, exit
End Function

chazrad

May 24, 2002, 2:37pm
"brant" <awteen at shoemakervillage.org> wrote in
news:3cee6570$1 at server1.Activeworlds.com:

> cells). The nested For loops are killing the processor, but I can't
> see any ways to eliminate them.

I am not going to win a popularity contest here, but VB is really not
the language to write these kinds of functions in. VB has a big overhead
in loading almost everything but the kitchensink,so having a lot of
internal processor drain already to take care of handling your calls to
it.

That's the prob with these kinds of highlevel languages, you're stuck
with how they handle things, if you want to change it you really have to
go down the ladder.

IMHO one can only improve on speed by having a 'bestquess' mechanism in
place coupled with a really tightly written assembly routine. In VB
these loops you cant really make really faster that it is worth the
effort.

If you want i dont mind to coop on a project to build some objects which
can be linked to your project....

Don't expect any blinding speed though ;)

grimble

May 24, 2002, 4:20pm
I think the way I would approach it (even in C++) would be to prebuild (and
maintain) a 40x40 cell array to cover the query area, and then, under each
cell (using the largest possible bounding box for each model), hold a list
of references to the models that MAY overlap it. That would obviously cut
down the checks to the objects that could feasibly be in the cell.

strike rapier

May 24, 2002, 4:22pm
This may sound completly stupid, what about some kind of method where its
like Binary Graphical usings arrays (no idea how it would be done.)

Give each cell a array name, and coords (2 dimensional for X and Y) then use
that with data to give each point in the cell Array a 0 to Gawd knows how
many value to show what objects it has on. If 1 obect tries to overwrite a
past array value and its not the same citnum u have encroachment?

I have no idea whatsoever if this would work, of even if its possable, it
just popped into my head...

- Mark
[View Quote]

chazrad

May 24, 2002, 4:31pm
"grimble" <grimble2000 at btinternet.com> wrote in
news:3cee8482 at server1.Activeworlds.com:

> I think the way I would approach it (even in C++) would be to prebuild
> (and maintain) a 40x40 cell array to cover the query area, and then,
> under each cell (using the largest possible bounding box for each
> model), hold a list of references to the models that MAY overlap it.
> That would obviously cut down the checks to the objects that could
> feasibly be in the cell.
>
>
>

that would be a very good idea, but that would entail a large overhead in
maintaining the list. again this is not very well managed in VB. in a big
world this really could stack up to a large chunk of memory, which has to
be indexed on a continous basis. imo it would be better to have some kind
of lookup list of possible neigbours, for example a walk would normally
have a walk next to it....and get some kind of inter/extrapolation.
something like a cd player, where it second quesses what should be there
when databits fall out.

strike rapier

May 24, 2002, 4:54pm
You really don't like VB do you?

Do u work for borland or something? *Sneaky suspicion*

silenced

May 24, 2002, 5:21pm
No, VB just isn't the best thing to be used.

BASIC is a beginners language and should be used for stepping up to other
languages that are more suited for programming. Hence Beginner's
All-purpose Symbolic Instruction Code. Note Beginners ;).

Sure it's great for kids to start, but that's what it's for, a start. You'd
be amazed at how much faster and smaller C++ programs are that do the same
thing.

--Bowen--

Have $3... want a website?
http://www.smartpenguin.com/affiliate.php?id=12

[View Quote]

strike rapier

May 24, 2002, 5:35pm
I was chatting with a friend about it a day ago...

I personally went for VB because I already knew a little and i understood it
with its if and elseifs etc better than something like C++. Although VB is
limited (as this damn too many objects on form warning is showing me) it is
very nice for bots as you dont have to use al the string sets and such
(which i presume you have to in C++) I personally intent to move onto VC++
or VC++.NET when i get the opertunity to learn it (my school has no
programming lessons whatsoever).

grimble

May 24, 2002, 5:40pm
Please don't turn this into another "C++ is better than VB" thread. If you
steer clear of huge amounts of classes there's no issue real with VBs
performance in something like this. I really don't see where the overhead
comes in. If you structure and reference the stores appropriately, there's
no great overhead on managing the array in terms on memory or speed.
Compiled VB code "number crunches" at comparable speeds to compiled C++.

The key to improving performance of anything is to move as much of the
process as possible out of repetitive tasks. Object placement is not the
time to go navigating a list of any reasonable size. Storage vs Performance
is always a balance and slightly larger memory usage is of no consequence
when it comes to avoiding a 2 second parse of a collection.


[View Quote]

silenced

May 24, 2002, 5:44pm
Mmm, stay away from microsoft stuff. Get borland, learn normal C++, then
get a different compiler if you so want. You should learn how to program
C++ before you get into that microsoft .net BS.

So once you do learn C++, you can switch right over to different platforms.
And not have to unlearn anything that Microsoft does that other things
don't.

Borland has a nice free C++ compiler as well. Great for learning. I make
my stuff with it still ;).

--Bowen--

Have $3... want a website?
http://www.smartpenguin.com/affiliate.php?id=12

[View Quote]

brant

May 24, 2002, 5:53pm
I appreciate the tips here, but I asked for help on the function, not the
language. As I said before, I had originally planned to write this program
in C++, but because I already have a lot of classes for various purposes
written in VB, I decided to use VB.

To tell you the truth, I don't think that any language will be able to
handle what this function is supposed to do perfectly, since it's just a
work-around for the same function in the world server. Just getting it to
work took four days - it'll take many more to get it optimized, and there
are time constraints (i.e. the release of version 3.3) to deal with here.
It would be interesting to see how Roland implemented this function in the
world server.

[View Quote]

brant

May 24, 2002, 5:59pm
Well, I could use all the help I could get in improving the speed of this
function, as it will probably be called ten million times over the next
year - if you'd like, I can send you the AWObjects class, the RegistryFile
class and their associated classes and you can take a look :)

[View Quote]

chazrad

May 24, 2002, 6:53pm
I wasn't trying to make this into a religious discussion, i just tried
to give some real advice, despite what Grimble says, no way VB is going
to stack up to c, or assembly any which day. My suggestion is to handle
the serious numbercrunching in a seperate module and call it from VB.

if not suit yourself but no way you're going to handle the requests that
your idea will generate. And for sure the Aw browser is not written in
VB


"brant" <awteen at shoemakervillage.org> wrote in
news:3cee9a34$1 at server1.Activeworlds.com:

> I appreciate the tips here, but I asked for help on the function, not
> the language. As I said before, I had originally planned to write
> this program in C++, but because I already have a lot of classes for
> various purposes written in VB, I decided to use VB.
>
> To tell you the truth, I don't think that any language will be able to
> handle what this function is supposed to do perfectly, since it's just
> a work-around for the same function in the world server. Just getting
> it to work took four days - it'll take many more to get it optimized,
> and there are time constraints (i.e. the release of version 3.3) to
> deal with here. It would be interesting to see how Roland implemented
> this function in the world server.
>
[View Quote]

silenced

May 24, 2002, 6:55pm
Of course it's not. It'd probably be something around 8 mb's and take 2
minutes to boot up.

--Bowen--

Have $3... want a website?
http://www.smartpenguin.com/affiliate.php?id=12

[View Quote]

jerme

May 25, 2002, 1:38am
Programming is a neat thing...

I don't know if everyone else has noticed.. The hardest part about
programming is learning the concepts, the logic, and the flow of a progam.
Learning how to break a problem down into pieces you can easily solve though
the programming language, and learning the loops/control statements is the
most important thing. These issues are common to every programming language.
BASIC and Visual BASIC are good for teaching these concepts. You can create
if statements, loops, and dumbed-down objects without having to worry of the
curly braces, strong typing, and all the other particulars of a language
like C or C++. However, one you have the BASICs down you can adapt all that
knowledge to another language just by learning the syntax.

I'll restate what's already been said... Start with VB and learn how stuff
works. Then move up to something like Borland C++. And yes, stay away for
the .NET crap. Avoid it like the plage. All high-level languages are much
the same, it's just a matter of learning the sytax. Once you know one, you
can pick up other very quickly.

-J


--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jeremy Booker
JTech Web Systems
(www.JTechWebSystems.com -- Coming Soon)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[View Quote]

jerme

May 25, 2002, 1:48am
first idea that comes to mind....

Have you thought about using a matrix (or matricies)? I'm not sure how you'd
exactly you'd apply them... just an idea.

-J

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jeremy Booker
JTech Web Systems
(www.JTechWebSystems.com -- Coming Soon)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[View Quote]

silenced

May 25, 2002, 5:29am
hehe, I hear an echo. :D

--Bowen--

Have $3... want a website?
http://www.smartpenguin.com/affiliate.php?id=12

[View Quote]

grimble

May 26, 2002, 10:15am
Just to close this daft and uninformed "VB is slow/crap" trash, I've now
implemented exactly what Brant described which has been tested with a 3x3
survey zone at three reasonably well populated locations including
AlphaWorld GZ. Below are summaries of the zones ("Models" is the number of
unique models used, "Objects" are the number of actual objects in the zone
and "References" is the total number of references to the objects - i.e. the
number of potential overlaps calculated using the origin of the object and
the maximum distance of a vertex from the its origin).

Area 1 - Models: 159, Objects: 3367, References: 27693
Area 2 - Models: 232, Objects: 3920, References: 31447
AlphaWorld GZ - Models: 316, Objects: 5792, References: 47476

If anyone can point me to an active building area where I can kick this in
for a few hours for some final testing, that would be welcome.

The maintenance of the cache performs acceptably ... showing a ZERO
execution time on all adds and deletes, while fully maintaining the objects
and their references in the zone and discarding all unwanted data/memory on
the fly. Using a max radius of 1000 (1 cell) for each object - from Brant's
code it looks like he already has this information for each object so there
was no need to replicate the scan of the model file - an encroachment check
on AW GZ is reduced to 63 objects which is negligable and will also show a
zero execution time. For info, a zero exec time calculated using the VB
Timer function represents significantly less that 1/100th of a second (if it
was just under 1/100th of a second, some calls would show a 0.01s exec time
but they're all 0.00).

I'm not going to share the code here, because it was put together for
Brant's use, and I'll leave it up to him whether he wants to post it in the
newsgroup. his project is, after all, "sekrit".

As a final note for all, writing performing VB applications is all about
using the right technologies and methods for each task. All VB objects
(including forms, controls and in-code objects such as collections, as well
as those instantiated from classes) are COM objects with the associated
overheads. COM is intended for interfacing, such as the objects exposed by
MS Office applications for use in VBA and not suitable for excessive
internal use. Every time you access an object in VB it must pass through all
the marshalling inplace to enable the object to be exposed outside the
application/component (although there is less of this for private classes,
it is still there). A few internal classes in an application is fine, such
as one for a world session table which allows all the session table related
function/data to be encapsulated. However, private data should be maintained
the "old-fashioned" way with user defined types, dynamic arrays and
appropriate management routines (ultimately not that different to writing a
class). Even if you intend to expose an instance of the internal data as a
class (such as an avatar in the session table example), the chances are it
would perform substantially better if a new object is created on-the-fly
from the internal stores when it is requested.

To demonstrate the difference, if classes and collections were used in the
code for Brant then memory is gobbled up quick as you like, and we've seen
from Brant's original post what the performance implications are. Using
structures and managed dynamic arrays, you get the performance I've
indicated above and minimal impact on memory usage. It all depends on a
balance between the number of accesses vs the internal overheads you face in
managing collections of objects.

I'll say again, compiled VB code performs comparably with compiled C++
code - THIS IS A FACT no matter what your prejudices. If you directly
convert VB code, as-written, to C++ (creating ATL classes for the each of
the coded and supplied classes used in VB) then that application would
perfrom roughly the same as the VB equivalent. Any programmer worth their
salt uses the language that best suits them, including the level of
expertise they have available on a given language and its suitability to the
task. Anyone that makes general claims that one language is "better" than
another or disparages a specific language off the cuff is a fool. Although
VB is a BASIC derivative in terms of syntax, anyone that sees that fact as
significant is sorely illinformed.


[View Quote]

chazrad

May 26, 2002, 11:19am
all power to you, Grumble. be happy with what you got, and leave silly
uninformed 25 years of experience as a professional writer people behind
you in the dust of your mighty wrath. :)

grimble

May 26, 2002, 11:30am
34 Year old with 16 years experience in the development of cross-platform,
enterprise and large-scale financial systems in a number of languages and
environments. Currently a self-employed software consultant working for
international companies. Bite me!

[View Quote]

jerme

May 27, 2002, 2:08am
lol..

Nice work grimms.. I'm sure Brant will be happy to hear of this :o)

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jeremy Booker
JTech Web Systems
(www.JTechWebSystems.com -- Coming Soon)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[View Quote]

agent1

May 27, 2002, 3:06pm
I *love* picking nits, so here I go ;)

It is impossible for anything to have a "ZERO execution time". Even a simple
assembly add operation takes time (however little).

-Agent1

[View Quote]

grimble

May 27, 2002, 4:11pm
*sigh* ... gotta say, didn't expect you to join the ranks of people who
can't keep a serious perspective on a development newsgroup. As I said only
two sentences further on ... "For info, a zero exec time calculated using
the VB Timer function represents significantly less that 1/100th of a second
(if it was just under 1/100th of a second, some calls would show a 0.01s
exec time
but they're all 0.00)." Make an effort will ya!

Why is it that people would rather say anything than have nothing to say at
all?

Grims

[View Quote]

agent1

May 27, 2002, 7:19pm
Well, I was only joking around, however...

You were making the claim that your code can do the impossible only later to
add "oh yeah... that's only because the timer I'm using isn't accurate
enough".

-Agent1

[View Quote]

grimble

May 28, 2002, 12:23am
[View Quote] Sorry ... I have very little sense of humour with this NG at the moment.

> You were making the claim that your code can do the impossible only later
to
> add "oh yeah... that's only because the timer I'm using isn't accurate
> enough".

;o) Do you really think I would write a post that size and making the
points I did and not have it say exactly what I wanted, how I wanted it to?
It was a qualification to ensure the point was clear ... ironically to avoid
comments like "Bullsh*t, zero exec time". I'll leave you all for a while I
think, and pass on anything I have to add to any threads by e-mail.

Grims

datedman

Jun 2, 2002, 6:52pm
I'm not sure how VN works, I detest it--however I love to optimize code. :)
One thing I can suggest is that you use > instead of >= since I don't know if VB
figures that out for itself and I suspect it does not.

Another thing I see happening is that you're comparing to awobj.x several times
and it's possible that VB will be faster if you assign this to a variable.

Also, you could put more parentheses in some expressions to make things more
clear to VB for instance in:

If (AWObj.Z - TempZ < CellZ And AWObj.Z - TempZ >=
CellZ + 1000) Or (AWObj.Z + TempZ < CellZ And AWObj.Z + TempZ >= CellZ -1000)
Then

In fact you could try coding this as separate if statements and see if that
helps.

You also have several places where you're subtracting tempx from awobj.x, assign
to a variable. Hmmm in fact, lemme see...oh Geez, how the hell does this thing
work? Hehe, either I am missing something drastic or "Xcounter" and "Zcounter"
are never used within the loops.

I still don't even see why yer looping so I'm real clueless here, but why the
hell would you set up step loops using xcounter and zcounter and then never
reference them within the loops?

[View Quote] > As part of the "sekrit project," I've been putting together hard-to-write
> functions while I wait for MrGrimm (a.k.a. 9 9 9) to finish the VB version
> of the new SDK. One of the most difficult parts of the project is being
> able to determine whether there are any objects in a cell that encroach into
> the cell. To explain this better, imagine that there is a single
> walk001h.rwx filling an entire cell that needs to be built. This function
> is supposed to determine whether there are any other objects either in the
> cell or overlapping into the cell that would cause the walk001h.rwx to be in
> a state of encroachment.
>
> While other parts of the project have been relatively simple, I've been
> working on this part for four days straight and have yet to find an
> acceptable solution. Yesterday night, I finally got the function to work
> correctly, but unfortunately, it can take up to two seconds(!) for each
> call. If 30 people are in AWTeen at a time and if just 8 of them perform
> the action that requires this function to be called two times per minute,
> the bot will be grinding away computing encroachment values for half the
> time! The problem is that it has to search through all of the AWObjects in
> a large collection that contains a 5X5 query result. I can reduce the load
> to deal with 3X3 queries only, but the wait is still ridiculously long.
> Someone suggested to me to implement a binary search, but doing so wouldn't
> help because it would be impossible to sort the objects in such a manner as
> to eliminate some of them, because some are obviously larger than others and
> some can be very large (i.e. that blue wall section that takes up five
> cells). The nested For loops are killing the processor, but I can't see any
> ways to eliminate them.
>
> The function is below. Any help anyone could provide in improving the speed
> on this one would be much appreciated.
>
> --------------
> 'CitNum is the number of the owner of the objects that should be ignored
> (i.e. the builder)
> Public Function CheckCellForEncroachment(ByRef AWObjectsCol As AWObjects,
> CellX As Long, CellZ As Long, CitNum As Long)
> Dim TempX As Long, TempZ As Long, XCounter As Long, ZCounter As Long
> Dim XCheck As Boolean
> Dim ZCheck As Boolean
> 'AWObj is an object representing an AW object - X here is the X
> coordinate, Z is the Z coordinate
> For Each AWObj In AWObjectsCol
> If AWObj.Owner <> CitNum Then
> 'This part takes care of the case when the object is actually in
> the cell
> If AWObj.X >= CellX And AWObj.X <= CellX + 1000 And AWObj.Z >=
> CellZ And AWObj.Z <= CellZ + 1000 Then
> CheckCellForEncroachment = True
> Exit Function
> End If
> TempX = mCol(AWObj.Model).X
> TempZ = mCol(AWObj.Model).Z
> XCheck = False
> ZCheck = False
> 'for loops are necessary in the case that an object fills more
> than two cells
> 'in this case, an object could acutally encroach by having both
> ends out of the cell
> 'in question, while the middle is in the building
> For XCounter = TempX To 0 Step -1000
> For ZCounter = TempZ To 0 Step -1000
> 'coordinates of objects in negative numbered cells are
> LOWER than the cell coordinate,
> 'while the coordinates of objects in positive numbered
> cells are HIGHER than the coordinate
> 'this, either the slow abs() function must be used, or
> an if else clause is needed
> If AWObj.X > 0 Then
> If (AWObj.X - TempX > CellX And AWObj.X - TempX <=
> CellX + 1000) Or (AWObj.X + TempX > CellX And AWObj.X + TempX <= CellX +
> 1000) Then
> XCheck = True
> End If
> Else
> If (AWObj.X - TempX < CellX And AWObj.X - TempX >=
> CellX - 1000) Or (AWObj.X + TempX < CellX And AWObj.X + TempX >= CellX -
> 1000) Then
> XCheck = True
> End If
> End If
> If AWObj.Z > 0 Then
> If (AWObj.Z - TempZ > CellZ And AWObj.Z - TempZ <=
> CellZ + 1000) Or (AWObj.Z + TempZ > CellZ And AWObj.Z + TempZ <= CellZ +
> 1000) Then
> ZCheck = True
> End If
> Else
> If (AWObj.Z - TempZ < CellZ And AWObj.Z - TempZ >=
> CellZ + 1000) Or (AWObj.Z + TempZ < CellZ And AWObj.Z + TempZ >= CellZ -
> 1000) Then
> ZCheck = True
> End If
> End If
> If XCheck And ZCheck Then
> CheckCellForEncroachment = True
> Exit Function
> End If
> Next
> Next
> End If
> Next
> CheckCellForEncroachment = False
> 'if no object is found that encroaches, exit
> End Function

kah

Jun 3, 2002, 1:51pm
"datedman" <russell at synergycorp.com> wrote in
news:3CFA8162.F824DCCC at synergycorp.com:

> I'm not sure how VN works, I detest it--however I love to optimize
> code. :) One thing I can suggest is that you use > instead of >=
> since I don't know if VB figures that out for itself and I suspect it
> does not.
>
> Another thing I see happening is that you're comparing to awobj.x
> several times and it's possible that VB will be faster if you assign
> this to a variable.
>
> Also, you could put more parentheses in some expressions to make
> things more clear to VB for instance in:
>
> You also have several places where you're subtracting tempx from
> awobj.x, assign to a variable. Hmmm in fact, lemme see...oh Geez, how
> the hell does this thing work? Hehe, either I am missing something
> drastic or "Xcounter" and "Zcounter" are never used within the loops.

First, > is different from >= because if you have X = 1 and Y = 1 and you
do If X > Y it will be false, but it will often be desireable to have it
evalute to true in this case. What's the point of assigning awobj.x to
another variable? It's already a variable, you'll be wasting time and
memory assigning it to another var :-)). Parantheses don't make much of a
difference, really (actually, I don't think they matter at all). Xcounter
and Zcounter are just a shortcut to have a loop, because the For var = X
to Y needs a var.

KAH

grimble

Jun 3, 2002, 2:39pm
With AWObj being an object (or rather a reference to an object), the method
itself is a function call. Worst of all though is the impact of referencing
objects in VB. All references to an object cause a temporary copy of the
entire object to be made on the stack, the method is then called and finally
the copy is discarded. This takes time and is done for EVERY reference. This
is why the With statement exists, where VB will create one copy on the
object and reference it throughout the block. For example, the following two
snippets of code do the same thing functionally, but under the covers they
work very differenly as you will see from the comments.

Version #1
var1 = AWObj.X 'Copy to stack, execute X method, discard stack copy
var2 = AWObj.X 'Copy to stack, execute X method, discard stack copy
var3 = AWObj.X 'Copy to stack, execute X method, discard stack copy
var4 = AWObj.X 'Copy to stack, execute X method, discard stack copy

Version #2
With AWObj 'Copy to stack
var1 = .X 'Execute X method
var2 = .X 'Execute X method
var3 = .X 'Execute X method
var4 = .X 'Execute X method
End With 'Discard stack copy

Therefore using something like objX = AWObj.X and then using objX for the
conditions would benefit the performance considerably, since objX is a
direct reference to the stack.

As for the XCounter and ZCounter loops, datedman's point is very valid.
Unless these values alter the environment somehow, either by being
referenced in the loop or controlling a counter or something similar, all
that is happening is that exactly the same values are being referenced. In
this particular code, the loop is just a loop, nothing else. If the subject
of the loop does nothing, then the loop is redundant. All the conditions
will evaluate to the same result in every pass of the loop since all the
values that ARE referenced (AWObj.X, TempX, CellX, AWObj.Z, TempZ and CellZ)
never change.

Grims.


[View Quote]

datedman

Jun 5, 2002, 1:18am
As I say, I know very little about VB. :)

However, read my message again and THINK before you reply. All my points are
actually valid to some extent, or may be. :) I'd hazard a guess that I was
optimizing code before you reached puberty. This is not a put-down, just a
simple statement of the fact that I've been doing this a loooong time and I
am actually quite good at it.

[View Quote] > "datedman" <russell at synergycorp.com> wrote in
> news:3CFA8162.F824DCCC at synergycorp.com:
>
>
> First, > is different from >= because if you have X = 1 and Y = 1 and you
> do If X > Y it will be false, but it will often be desireable to have it
> evalute to true in this case. What's the point of assigning awobj.x to
> another variable? It's already a variable, you'll be wasting time and
> memory assigning it to another var :-)). Parantheses don't make much of a
> difference, really (actually, I don't think they matter at all). Xcounter
> and Zcounter are just a shortcut to have a loop, because the For var = X
> to Y needs a var.
>
> KAH

silenced

Jun 5, 2002, 1:47am
> As I say, I know very little about VB. :)
>
> However, read my message again and THINK before you reply. All my points
are
> actually valid to some extent, or may be. :) I'd hazard a guess that I
was
> optimizing code before you reached puberty. This is not a put-down, just
a
> simple statement of the fact that I've been doing this a loooong time and
I
> am actually quite good at it.

Well.. If you know very little about VB, and I know KAH knows a damn lot of
it.. it wouldn't make sense to tell him he's wrong. Just my opinion.
Optimizing code before he reached puberty makes you a better programmer?
I've seen 13 yr olds that just learnt a language show up a teacher that's
been a system programmer for 20 years. The longevity of your time with a
language has little value of your experience really.. but that's also my
opinion. No offense intended if you took any offense :D

--Bowen--

Have $3... want a website?
http://www.smartpenguin.com/affiliate.php?id=12

1  2  |  
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2024. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn