Page 1 of 1

ALCHP and LOAD problem

Posted: Tue Jul 30, 2019 2:59 pm
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!

Re: ALCHP and LOAD problem

Posted: Tue Jul 30, 2019 7:05 pm
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

Re: ALCHP and LOAD problem

Posted: Wed Jul 31, 2019 9:11 am
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).

Re: ALCHP and LOAD problem

Posted: Wed Jul 31, 2019 9:57 am
by Martin_Head
Thanks for that. It's me just getting old.

Re: ALCHP and LOAD problem

Posted: Wed Jul 31, 2019 10:13 am
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

Re: ALCHP and LOAD problem

Posted: Wed Jul 31, 2019 10:46 am
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?