[comp.os.msdos.programmer] farmolloc and malloc

jeff@u02.svl.cdc.com (Jeff Needham) (02/09/91)

This is posted on behalf of someone without Net access
I will forward all responses

jeff

I am using Turbo C++ on a PC clone with 1MB of RAM. Actually, I'm not using
any of the OOP stuff; just writing vanilla C programs.

No matter what I try, or how small my program is, I find that "malloc" and
"farmalloc" allocate space in the same segment, which starts out at about
62000 bytes long. At the very least, I wish they could use two different
segments of that size. At best, I wish "farmalloc" could allocate different
segments until available RAM is exhausted.

My test program uses "coreleft" and "farcoreleft". They seem to give the
right answers, agreeing with the point at which "malloc" or "farmalloc"
returns a NULL pointer.

What am I doing wrong, or neglecting to do ?
--
Waiting for the Oracle port to the Oberheim OB-Xa
| Jeffrey Needham
| Yet Another Oracle Performance Group
| Control Data - Santa Clara, CA - INTERNET jeff@hawk.svl.cdc.com

dhesi%cirrusl@oliveb.ATC.olivetti.com (Rahul Dhesi) (02/09/91)

In <30456@shamash.cdc.com> jeff@u02.svl.cdc.com (Jeff Needham) writes:

>No matter what I try, or how small my program is, I find that "malloc" and
>"farmalloc" allocate space in the same segment, which starts out at about
>62000 bytes long. At the very least, I wish they could use two different
>segments of that size.

Typically when you call malloc or farmalloc, they will allocate memory
sequentially, allocating as many bytes as you ask for, and always
allocating the next block from roughly where the previous bllocation
left off.

In Intel CPU-based machines, the concept of "same segment" exists only
before the program is linked.  Once it is linked and loaded, memory is
in a linear address space, and only its *addressing* is segmented.
(The CPU knows about segments but the memory hardware does not.)  The
real memory address is always linear, but it can be expressed in
different ways using different values for segment and offset.

So, if you want to treat different blocks of memory as being in
different segments, you can do so, but it has nothing to do with how it
is allocated.  Just assign any combination of segment and offset to
your registers.  Any two memory addresses that are within 64K of each
other can be assumed to be either in the same segment or in different
segments, as you prefer.  Memory addresses that are further than 64K
apart as in different segments because you must reload your segment
register between references.
--
Rahul Dhesi <dhesi%cirrusl@oliveb.ATC.olivetti.com>
UUCP:  oliveb!cirrusl!dhesi