ALCHP and LOAD problem

Anything QL Software or Programming Related.
Martin_Head
Gold Card
Posts: 419
Joined: Tue Dec 17, 2013 1:17 pm

ALCHP and LOAD problem

Postby Martin_Head » Tue Jul 30, 2019 2:59 pm

I don't know if I am just going a bit potty, but...

I have noticed a problem in SMSQ/E with ALCHP, where LOAD will corrupt the allocated space.

Start SMSQ/E (I'm using QPC2 as an example)

type x=ALCHP(12000), then PRINT HEX$(x,32) and make a note of the address.

In my case it returned $00140404

type PRINT PEEK_L($140404), returns 0 as expected. PRINT PEEK_L($140408) also returns 0 as expected.

LOAD a BASIC program, I don't know if size is important, but I used one about 8K long.

Now do the two PEEK's again. The allocated space has been corrupted!


User avatar
tofro
QL Wafer Drive
Posts: 1586
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: ALCHP and LOAD problem

Postby tofro » Tue Jul 30, 2019 7:05 pm

That is actually intentional.

SBasic Reference Manual wrote:NOTE 2

Memory reserved by ALCHP is indirectly cleared by NEW, CLEAR, LOAD and LRUN (this does not apply to the Btool extended variant - see above).


As LOAD clears all variables, it would be hard to free any ALCHPed space after a LOAD (without at least pen and paper to take note) and you would end up with possibly severe memory leaks after a while.

I think ALLOCATION from Turbo toolkit provides memory that survives NEW and LOAD.

Tobias


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
mk79
Gold Card
Posts: 359
Joined: Sun Feb 02, 2014 10:54 am

Re: ALCHP and LOAD problem

Postby mk79 » Wed Jul 31, 2019 9:11 am

You can also use RESPR if you want the memory to survive a NEW (it will try to use the resident procedure area but fall back to the common heap if that isn't possible).


Martin_Head
Gold Card
Posts: 419
Joined: Tue Dec 17, 2013 1:17 pm

Re: ALCHP and LOAD problem

Postby Martin_Head » Wed Jul 31, 2019 9:57 am

Thanks for that. It's me just getting old.


tcat
Super Gold Card
Posts: 550
Joined: Fri Jan 18, 2013 5:27 pm
Location: Prague, Czech Republic

Re: ALCHP and LOAD problem

Postby tcat » Wed Jul 31, 2019 10:13 am

Hi Martin,

To retain basic variables, I use MERGE in lieu of LOAD as I test various M/C against different basic test units.

Code: Select all

DLINE TO: REMark deletes old prog, but vars
MERGE prog_bas: REMark loads new prog
CLEAR: REMark optional smashes var area

Tomas


Martin_Head
Gold Card
Posts: 419
Joined: Tue Dec 17, 2013 1:17 pm

Re: ALCHP and LOAD problem

Postby Martin_Head » Wed Jul 31, 2019 10:46 am

What I had done, is write a small boot loader program to LBYTES and CALL some SuperBASIC extensions. Then LOAD a test program for the SuperBASIC extensions, which I was going to trace through with QMON/JMON.

Only I mistakenly used ALCHP instead of RESPR. And when I tried the extensions, Crash...

With all the extension code getting corrupted after the LOAD. And I thought, what the hell's going on?



Who is online

Users browsing this forum: No registered users and 7 guests