OK, if that's the case then it's something I did not know.

I always thought that ALL parameters were passed byval unless explicitly passed byref. Meaning that changes made to the passed variable were not reflected in the original object. I now see that this is true only for base data types (strings, integers, doubles etc).

Is there any harm in explicitly declaring the graphics parameter byRef??? I like explicitly declared code, I find it easier to keep track of my variables. I'm really not a fan of the linker "taking care of stuff" for me unless I explicitly declare it. It's what made me start this thread in the first place (it was changing the name of a parameter I passed ByRef from "CanvasName" to the expression "self.CanvasName", and of course you can't pass expressions as ByRef)

If it is an issue (and please let me know if it is, testing hasn't proven it one way or the other) I'll just have to break my habit.

It's nice to know there's still stuff I don't know after all these years though....

- Tom



On 18/02/2007, at 9:30 PM, Andy Dent wrote:


On 18/02/2007, at 6:45 PM, Tom Benson wrote:

There is a factor, though not significant.

The resulting image from all the graphics operation I perform is huge, in the tens of MB's.

Accessing the graphics of the canvas ByRef enables me to draw directly to the original object, instead of duplicating the current content and then passing the resulting graphics object back to the container.

It doesn't make much of a difference for smaller routines. but this routine is physically to big to be contained in a single method, even too big for two, so I have split it up into 34 different block drawing sub routines.

As an aside, passing the graphics object ByRef means that two or more of these sub routines can operate simultaneously (well, not simultaneously, but co-operatively) on the graphics object at the same time. Which is necessary for this app, as for why it's necessary it's a little difficult to explain...

Tom, maybe I'm not getting something, but what about your explanation makes you think ByRef enables it as opposed to a normal object pointer?

Anything other than a primitive data type like an integer IS passed "by reference" in Pascal terms (or in C terms, as a pointer).

Say you have something like
sub MangleImage(g as Graphics)

When you call MangleImage with MyCanvas.Graphics, the reference count in MyCanvas.Graphics is updated and MangleImage receives the same reference to a Graphics object as exists in the MyCanvas property.

There's no copying of MB's occurring.

In fact, I can't think of a circumstance where passing a Graphics object ByRef could *ever* make sense - the advantage of using ByRef means you can create a new object and return it in the parameter but Graphics objects are always externally supplied by the framework, not things you should be creating in your code.

regards

Andy
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to