Hi,
With that being said, can you use PROC NEAR for some code and PROC FAR for others?
Yes, but as Dave said, it is not often that you would want to.
Maybe if you wrote a subroutine library or some such.
Also, regarding to the segments, do some memory block just get automatically allocated as a certain segment or is it always a specific memory block? Say for DOS, since only one segment,
does it just generate 64kb of memory randomly for your program to use?
Usually DOS will load your program in the first available memory.
If you have more than one segment in your program, you can
specify the load order, but they will normally be loaded one after
another with no wasted space. (Give or take.)
For a .COM program DOS allocates all available memory. For an .EXE program DOS allocates enough memory to contain the program image and the PSP, plus any additional memory specified in the EXE header.
The default for either a *.COM or *.EXE program is to allocate
all memory to the program. There are LINK options to limit memory
to a lesser value (and programs to edit the EXE header to do the
same thing), but I have seen very few programs that actually do
that.
Right, but EXE programs are often very memory hungry, too. So it's necessary to shrink
the memory for the EXE if you need a dynamic buffer during run time.
I wrote a program using a variable sized buffer that just uses
the memory following the program without deallocating/reallocating
the memory. I just set a segment register to the end of the program,
and incremented it for each additional data item. Use information
from the PSP to locate the end of the memory allocated to the
program. (And have a whole bunch of fun when your {my} math
does not add up.) I think the shrink/allocate paradigm is a hold-over
from C programming. Or it could be that I am just lazy.
you are more likely to use multiple data segments
Yeah. Up to a few thousand 48 byte "fake" segments in the
above mentioned program. I have also written programs that
had data arrays that exceeded the normal segment limits and
thus required more than one data segment.
Regards,
Steve N.