Microsoft C - Heap space question

D. Chadwick Gibbons chad at csd4.csd.uwm.edu
Thu Sep 7 11:31:50 AEST 1989


[yuck!]

In article <3631 at cbnewsh.ATT.COM> jmn at cbnewsh.ATT.COM (john.b.medamana) writes:
|Is it possible to get a separate physical segment (Group?) 
|for heap?

	Normally? No, I don't believe you can.  However, there is an easy way
to get more heap space--which is what I assume you want.

	MicroSoft, and most other DOS compilers for that matter, provide a
function to allocate heap space using far pointers.  This way, if the heap
requirements exceed 64K, it will grab another chunk of system memory.  The
function is declared--I believe--as "char far *farmalloc(size_t);"  Note the
far pointer, rather than the normal, "near", pointer.  If you are using the
large memory model, there should be no problem--all pointers are converted to
fars and thus all pointers are thirtyt-two instead of sixteen bits wide.  Be
sure to read the rules on using far pointers to understand the differences and
what, if any, code you might have to modify.  In general, make sure you
declare your pointers explicitly far.

	One very important note about farmalloc: usually, it will grab memory
that was not original assigned to the executable when it ran.  Therefore, upon
normal terminal exit (via exit) this memory _will not_ be returned to the
operating system.  To avoid "Insufficent Memory" errors later down the road,
be sure to explicitly free this allocated memory.  I believe farmalloc has a
corresponding free function called farfree, but check for user's guide to be
exact on it's usage.

	Are sixteen bit segmented systems wonderful, or what?



More information about the Comp.lang.c mailing list