[net.micro.pc] Changing Memory Allocation...

BILLW@SRI-KL.ARPA (02/16/84)

From:  William "Chops" Westfield <BILLW@SRI-KL.ARPA>

I'm having trouble with the memory allocation function call
of MSDOS (this is actually on an HP150), i.e. code 4Ah.
It returns Error Code 7 (internal stuff trashed), even
on a freshly booted system.  Is there something tricky
about this call ?

Thanks
Bill W

BRACKENRIDGE%USC-ISIB@sri-unix.UUCP (02/17/84)

From:  Billy <BRACKENRIDGE@USC-ISIB>

You aren't the only one confused by this call. I searched through the
archives and came up with an earlier discussion of the subject.  We are
really getting quite an extensive data base on MS-DOS and PC related
problems.  Of course the index is just vague memories of past
INFO-IBMPC discussions helped out with a string search command.

You might contact Darrel Plank, if that proves fruitless this is the
sort of problem Microsoft has been responsive to in the past. I assume
these memory allocation functions get to be more important when one is
designing programs to run under Microsoft Windows.

Date: 14 Nov 83 8:28:56-PST (Mon)
To: info-ibmpc @ Usc-Isib
From: ihnp4!ihlpf!dap1 @ Ucb-Vax
Subject: Memory Allocation in DOS?????

I have been trying to get the DOS 4bh interrupt (exec) to work from
Lattice C.  The return code said there was insufficient memory.  I
assumed this was due to not doing a 4ah interrupt first (SETBLOCK).
Unfortunately, this interrupt is not explained very well.  It talks
about "blocks" which I assume are the blocks assigned by interrupt 48h
(Allocate Memory).  Does this mean that I have to "allocate" memory
just so I can turn around and "free" it?  If so, where is this memory
allocated from?  Lattice C sets up the data and stack segment just
behind the code segment.  How does DOS know that Lattice is using this
64K?  If it doesn't know, does it wipe out my stack and data segment?
Or does it allocate memory from the top of memory down, in which case
I'll have to determine just the right size to ask for.  Alternatively,
could I ask for 256K and get the size of the "largest block of memory
available" in BX, subtract 64K from it and request that size block?
Of course this all seems rather silly, since I only WANT it so I can
immediately DELETE it.  Does anybody have a clue as to what these
routines REALLY do??????

                                                Thanks in advance,
                                                Darrell Plank
                                                BTL-IH

Date: 15 Nov 83 3:00:40-PST (Tue)
To: info-ibmpc @ Usc-Isib
From: ihnp4!ihlpf!dap1 @ Ucb-Vax
Subject: "Re: Mem. Alloc. in DOS????? - (nf)"

Well, I have figured out some stuff since last night when I posted the
original note.  I got my exec() system call for Lattice C working, but
only on .com files (generated under Lattice by linking with cc.obj
rather than c.obj).  I could not get function 4a to work in a .EXE
file.  In a .com file you just pass the value of the ES register upon
entry and the size in paragraphs in the BX register.  I haven't the
foggiest what goes in the ES register for .exe files.  I tried sending
the segment with the PSP, the CS segment and finally, the segment just
beyond all the memory I was using (although I don't see how DOS could
distinguish that, so it didn't surprise me that it didn't work).  None
of them worked.  I always got an error code 7 back which means "Memory
control blocks destroyed".  It seems as though the note on P. D-47 of
the DOS Manual which says "When your program received control, all of
available memory was allocated to it" only applies to .com files.  The
only hint that the manual makes of this distinction is on PPs. E-6 and
E-7 where the fact that all the memory is allocated to the program
seems to apply only to .com files.

	What is going on here?  If there is a distinction, why didn't
they mention it in the function calls???  Why does such a distinction
exist?  Is it totally impossible to deallocate memory from a .exe file
and hence to exec from it???  Whatever the case, I think they did a
lousy job of documenting this feature.

                                              Darrell Plank
                                              BTL-IH

P.S.  I got a request to post the "exec" function which is modified
from a macro put up by Brad Davis a while back.  I'll do this shortly
so maybe I can save other people the headache of trying to figure out
the difference between the DOS documentation and DOS itself.