ALCHP and LOAD problem

Anything QL Software or Programming Related.
Post Reply
Martin_Head
Aurora
Posts: 847
Joined: Tue Dec 17, 2013 1:17 pm

ALCHP and LOAD problem

Post by Martin_Head »

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
Font of All Knowledge
Posts: 2685
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: ALCHP and LOAD problem

Post by tofro »

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
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: ALCHP and LOAD problem

Post by mk79 »

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
Aurora
Posts: 847
Joined: Tue Dec 17, 2013 1:17 pm

Re: ALCHP and LOAD problem

Post by Martin_Head »

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


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

Re: ALCHP and LOAD problem

Post by tcat »

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
Aurora
Posts: 847
Joined: Tue Dec 17, 2013 1:17 pm

Re: ALCHP and LOAD problem

Post by Martin_Head »

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?


Post Reply