|
From: John S. <joh...@ja...> - 2025-10-02 22:20:41
|
Actually, I can use the "const" keyword.
I just had to change:
FXArray<Test>* arrayPtr;
To
const FXArray<Test>* arrayPtr;
-----Original Message-----
From: John Selverian <joh...@ja...>
Sent: Thursday, October 2, 2025 6:04 PM
To: je...@fo...
Cc: fox...@li...
Subject: Re: [Foxgui-users] passing FXArray by reference
That did it, save me about 2 seconds but it was tying up the UI so it's nicer now.
I had to use:
arrayPtr ->at(i)
Instead of this:
arrayPtr->[i]
I also had to get rid of the "const" keyword. That is what was messing me up before when I tried this.
thanks,
-----Original Message-----
From: je...@fo... <je...@fo...>
Sent: Thursday, October 2, 2025 11:13 AM
To: joh...@ja...
Cc: fox...@li...
Subject: Re: [Foxgui-users] passing FXArray by reference
On 2025-10-02 09:18, John Selverian wrote:
> I understand pass-by-reference (usually).
>
> However, this this case it seems my variable is complicated and I
> can't get the calling/declaration correct.
>
> Passing it the way I'm doing it now works without a copy until I get
> to the line "_testArray = testArray;" in class I'm passing it to.
>
> I don’t see how to assign the passed pointer to a pointer in the
> class...or how to declare the testArray variable in the class I'm
> passing it to so it is a pointer to an FXArray< Test >.
>
>
>
>
> In my main program I declare it like this:
>
> FXArray<Test> _testArrayMain;
>
> And I pass it like this:
>
> Search search (_testArrayMain);
>
>
>
> In the class I’m passing it to I have this:
>
> In the header:
>
> Search (const FXArray< Test >&);
> FXArray<Test> _testArray; // I don’t know what this declaration should
> be so only the pointers are assigned without a copy
>
> In the class source:
>
> Search::Search(const FXArray< Test >& testArray) {
> _testArray = testArray; // this line triggers the copy of all of the
> data }
OK, now we see your problem. But at least know this, passing by reference parameter has halved the number of copies, at least.
Consider maybe declaring things in terms of pointers, instead:
member variable:
FXArray<Test>* arrayPtr;
then
setTheArray(FXArray<Test>* ptr){
arrayPtr=ptr;
}
Then access array i as:
arrayPtr->[i]
This accomplishes the whole enchilada with zero copying [thus, very fast]. Now you just need to remember who actually "owns" the array i.e. where in the s/w the array will eventually get deleted.
This could be FXAutoPtr<FXArray> so you can't forget deleting stuff when it goes out of scope.
-- JVZ
_______________________________________________
Foxgui-users mailing list
Fox...@li...
https://lists.sourceforge.net/lists/listinfo/foxgui-users
|