PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

List Behaviour Query

You may remember I posted a Zip archive with some list test code (list of structures) for which Kornalius made some corrections for 0.7a and 0.7b.

Those changes work fine ....

However I have a question with respect to the command:

goto (MyList$,index$);

The documentation infers that the range of index$ is 0 .. count(MyList$)-1. My tests would imply this is not true. The range is 1 .. count(MyList$).

goto (MyList$,0); appears to point at the element of the list last referenced from a foreach (MyList$)loop or from an add/insert (MyList$) statement.

True or False?

I have included the zip archive with added code loop to demonstrate what I am saying. Run the test as Test/Test #1 and don't forget to transfer the mylist ascii text file to the application directory (all as before)


regards
Attachments:
list_test.zip (7 KB)
PointOfLight · 20 Aug 2004, 13:45 UTC
I believe there is a bug with the goto command when the list contains structures. I've attached a modified version of your code that just writes the first line of each record from your file as a string to the list. The foreach still works fine, and the loop (going from 0 to count - 1) works as you would expect it as well.
Attachments:
list_test.zip (7 KB)
While working on the Visual Form Builder written in PPL, I noticed a few problems with the linked-list using structures. I use that intensively in the VFB and made some corrections. The GOTO and LPOS are 0 index based now.
Thanks for the reply.

I'll leave my routine "as is" but "1-based" for the moment so I can get on with writing. It will be very easy to change when the next version comes out.

cheers
On further investigation I might wait for the next update to PPL.

The issue may be a little more complex than a simple index range issue. Even for lists of structures the goto command appears to vary between zero and one based. The "LPOS" function always returns a one-based index.

Also, I have an example where the goto (MyList$) call appears not to move the element pointer at all. However if I simply add a call to "LPOS" in the code the goto then works correctly

The code example below demonstrates ... simply commenting out the first "memo_addline" changes the name of the map shown in the second line.

Code:

Proc LoadMapByIndex(ndx$)
if ((ndx$>=0) and (ndx$<count(MapList$)))
goto (MapList$,ndx$); //may need change after 0.8
memo_addline(memo1$,"LPOS: "+LPOS (MapList$));
memo_addline(memo1$,"Loading Index="+str(ndx$)+" Map="+^MapList.name$);

// add actual code here to load a map ....

end;
end


Kornalius may have picked up all these errors in his corrections-to-date, but thought I better add these comments just in case.
Yep, LPOS was one-based index indeed. I have fixed it also. The whole list system has been updated a little in v0.8.

Are you interested in a pre-release of v0.8? If so please email me (same email that i use for announcements).
Kornalius,

Thanks for the email. I have installed the two files and confirmed that both (from the PIDE and from PPL on the PPC) identify as V0.8.

The LPOS function appears corrected. It now consistently reports a 0-based position as expected.

The bad news is that the "goto" problem still remains. The key bit of information that may lead you to the offending code is as per my example above ... if I execute a "goto" the list element does not appear to change (as evidenced by a debug print statement that displays a field from the selected element - it remains pointing to the last element "added"), but all I have to do is use the LPOS function immediately after doing the "goto" and all is perfect.

regards
Hi,

I will take a closer look at the goto() function tomorrow. What is strange is that I am currently in the process of writing the Visual Form Builder in PPL and I use the goto quite alot and I don't problems with it. It might be in some cases only I guess. I will investigate further tomorrow and get back to you.
Merv,

Any updates on the Goto() function behavior? Can you send me a little piece of code that doesn't work? I would love to fix this one tomorrow if possible.
Hi Kornalius,

Haven't had a chance yet and must go out for a couple of hours now (10:00am here), but I will definitely have something for you before the end of the day here (1200UTC). This should give you a little time to look at it during your day. At this stage I have not confirmed that the problem is even yours, so there may be nothing for you to do. If I do find anything I will attempt to package a program/code example that you can run to test.

BTW: The "garbage-collection" changes in the latest release have worked well. The code was leaking about 1Mb of memory every minute. Now its nearer to 16Kb per minute and I am sure this is probably related to something stupid I am doing so will take a closer look as soon as I get a chance, but for all practical purposes my program is "useable".

Thanks for everything ....
No problem, I am going to bed right now and tomorrow I will look at it.

If you managed to find the piece of code that seem to be leaking, please let me know and show me the code. I will do my best to fix the leak, if it's within PPL's internal.
mervjoyce · 25 Aug 2004, 06:23 UTC — More on "Memory L:eaks"
Hi Kornalius,

I think I have found a memory leak with the "StrToList" function BUT it only appears when this function is used in a "func". Performing StrToList calls in a tight loop is OK, but the same code in a func which is called in a tight loop leaks heavily.

Calling a func that includes other "standard" use of a list variable does not appear to cause a problem.

The attach code is an attempt to "test" some scenarios.

Compile and run the code. There are three test scenarios.

To start a test use:

Tests/Test#1, or Tests/Test#2, or Tests/Test#3.

To Stop a test use:

Flags/Flag#1, or Flags/Flag#2, or Flags/Flag#3.

Every 10 secs the "Free Memory" is printed out". You will note that Tests #1 and #2 are reasonably stable, but Test #3 leaks badly.

I am always very wary of the "test enviroment" influencing the outcome so please feel free to point out any limitations you see ....
Attachments:
memleak.zip (5 KB)
mervjoyce · 25 Aug 2004, 06:50 UTC — "goto" Update
Hi Kornalius,

Just a quick "interim" update.

This is the code procedure I created to get around the problem I am having:

Code:

proc mygoto(MyList$,ndx$)
local (i$);

i$ = 0;
first (MapList$);
while (i$<count(MapList$))
if (i$ == ndx$)
i$ = count(MapList$);
else
i$ = i$ + 1; next (MapList$);
end;
end;
end;


The problem is that in some instances within my program the use of

goto (MapList$,index$)

results in "no change" to the MapList index position (the index is a valid value). If I replace the line with

mygoto (MapList$,index$)

using the call to the above proc then everything is OK.

I have just confirmed that replacing all that code within my proc ("mygoto") with a single line

goto (MapLIst$,index$);

fails as it has in the past - eg the list index does not change.

I am attempting to see if I can create some code in my "test environement" that will reproduce this situation. I can then send you the code. It would be difficult for you to extract the necessary clues from my actual program source - it would need several large support files (bmp map files) for you to be able to run it (probably 10Mb+). Best if I can reproduce it in a "limited" environment.

regards
mervjoyce · 25 Aug 2004, 08:09 UTC — "goto" Test Code
Hi Kornalius,

I have attached some sample code that demonstrates the "goto" issue I have been referring to.

Load and compile the project. Copy the file "MapList" to the application directory. Run and start the test with:

Tests/Test#4

Hopefully the print-out explains.

The included text file (goto-test.txt) is a copy of the test screen when the code is run here.

Updated: 09:45UTC (incl attachment)

regards
Attachments:
goto-test.zip (10 KB)
Hey Merv,

I fixed the garbage collection for temporary strings. They are now released right after they are used. Therefore not being accumulated in the garbage collection memory and only cleaned after the procedure or function is done. It should leak a lot less now! I will have a new pre-release version available here sometime today.

As for the goto() function, I think I know why you think it's not working. The goto() returns a true or false wheter it could reach the index location or not. If it couldn't then the index pointer stays the same. I am pretty sure you are trying to move past the end of the list. In your procedure MyGoto(), the next() function won't allow to past the end, therefore, the index pointer will always be the last one if you try going past the list.

Now I have one question, do you think I should make the goto() behave like your MyGoto() procedure? I know it's pretty to check all the time for goto() to see if it can go or not to the index position asked.

Let me know...
Hi Kornalius,

Thanks for the garbage collection changes.

I am not sure I understand your comments on "goto".

You say that "goto" can return "true"/"false" as to whetehr it was able to move the pointer. If the index parameter is out of range it will return false and the pointer will not be changed. That makes sense.

In the sample I sent to you I pass the same arguments to both procedures:

goto(MapList$,3) and
mygoto(MapList$,3);

after calling "goto" the pointer refers to the last position in the list (eg the last map loaded [#10] - eg: it has not changed.

after then calling "mygoto" it the pointer has been changed to point to the correct [#4] map. The code in "mygoto" is working correctly!

The pointer is originally at the last item in the list - after the initial load. The list contains 10 elements. When I call "goto" I pass a parameter of "3" (eg looking for the 4th element). Are you saying "goto" will not move backwards in this scenario?
You got it right. However Goto() should move in any direction. I will test it again tomorrow. Damn I want to fix this problem. :)