Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

URGENT TURBO C++ MEMORY QUESTION

334 views
Skip to first unread message

Lee Perkins

unread,
Nov 23, 1994, 8:34:02 PM11/23/94
to
In article <3b0i4o$m...@nntp.Stanford.EDU>,
tre...@leland.Stanford.EDU (John Alfred Trezza) wrote:
<
< *The Problem*
< How do I use extended memory and allocate sizes that are large (say 1 Meg) ?
<
< Turbo C has a program called EMSTEST and I ran that and it executed ok, so I
< assume that it can be done (i.e. I'm doing something wrong).
<
< What am I doing wrong? Is there some compiler option I've missed? A header
< file? A library? Bad Code?!!! Keep in mind that I come from Unixland where
< there is no farmalloc and I don't have to deal with segmented memory...
<

farmalloc can only allocate memory from the base 640K. It differs
from malloc only in the fact that it can allocate memory larger than
1 segment (64K). If you want to access EMS or XMS, you can get a
third party library for handling memory above 1 meg, or you can
access your memory manager (EMM386) through interrupt calls. I
don't recall the interrupt(s) you need to access, but I'm sure
someone else out there in INTERNET land will know.

+-----------------------------------------------+---------------+-----------+
| ___ ________ ________ ______ | le...@infi.net | \-/\-/\-/ |
| /_ /| /_______/| /_______/| /_____/\ | Norfolk, VA | /-\/-\/-\ |
| | | | | ____|/ | ____|/ | _ \/| |---------------+-----------+
| | | | | |_ /| | |_ /| | |_| | | | What do you like to see |
| | | |____ | _|/___ | _|/___ | ___|/ | in a CRPG? Top-Down? 1st |
| | |/____/|| |/____/|| |/____/| | | | | person view? What type |
| |_______|/ |_______|/ |_______|/ |__|/ . | of combat system? If you |
| | have rp'd before, what's |
+-----------------------------------------------+ some of your favorite ad- |
| ventures? What do you (dis)like about CRPGs? E-Mail me your opinions... |
+-----------------------------------------------+---------------------------+
--

John Alfred Trezza

unread,
Nov 23, 1994, 6:10:16 PM11/23/94
to
I am posting this for a friend...
Please either respond in the newsgroup or to the e-mail
address at the end of this message. THANKS A LOT FOR THE
HELP. THIS IS A FAIRLY URGENT QUESTION for a program being
written at home. ANY ADVICE WOULD BE MOST WELCOME!!
Again, either respond in the newsgroup,
or, (better yet) to the e-mail address at the end of the post.
You can also send e-mail to me, the poster, if you like.
--john trezza


In general, the problem deals with using extended memory in Turbo C++


Specifically, here is a bit of code that I can't get running

Here's the program:
/* main.c */
#include <stdio.h>
#include <dos.h>
#include <alloc.h>

int main(int argc,char *argv[])
{
char huge *buffer;
unsigned long size;

size = 600*800; /* pick some very large size */
buffer = (char huge *)farmalloc(size);
if (!buffer)
{
/* quit */
}
/* continue */
}

The program is compiled with large or huge memory model using Turbo C 3.0.
tcc -mh main.c

I've turn on extended memory using
device=emm386.exe ON 5000 [whatever it is...]

and let's say I've got about 4 Meg free extended memory.
Also, suppose I have 512K free conventional memory.

When I run my program, farmalloc is allocating from conventional memory.
I discovered this by setting size to be a large number that *just barely*
doesn't fit in conventional memory, running MEMMAKER, and running the program
again; there is now enough space because I now have (for example, 550K) enough
conventional memory. Extended memory is not being used.

*The Problem*
How do I use extended memory and allocate sizes that are large (say 1 Meg) ?

Turbo C has a program called EMSTEST and I ran that and it executed ok, so I
assume that it can be done (i.e. I'm doing something wrong).

What am I doing wrong? Is there some compiler option I've missed? A header
file? A library? Bad Code?!!! Keep in mind that I come from Unixland where
there is no farmalloc and I don't have to deal with segmented memory...

Thanks,
-cathy

Cathleen Miller
Oracle Alert/Applications Object Library
cmi...@us.oracle.com
(415) 506-2321


shaun bellingham

unread,
Nov 25, 1994, 11:38:45 AM11/25/94
to
In article <3b0i4o$m...@nntp.Stanford.EDU>

tre...@leland.Stanford.EDU "John Alfred Trezza" writes:

> In general, the problem deals with using extended memory in Turbo C++
>

Aha, unfortunately you can't just do this. (EMSTEST presumably uses EMS, which
switches memory pages in and out of (emulated) expanded memory).To directly
access extended memory requires switching into protected mode (no direct access
to > 1Mb is possible with a processor in real mode) which is a bit more of a tin
of trilobites. So, either use EMS calls, or write protected mode code (you have
to switch in and out of it for DOS things) or use the blindingly simple approach
that the next, more knowledgeable poster, is about to post. I can feel him/her
typing as I type. Good luck, it's a pain.

-shaun.

Geoffrey Schmidt

unread,
Nov 25, 1994, 3:29:00 PM11/25/94
to
-> When I run my program, farmalloc is allocating from conventional
-> memory. I discovered this by setting size to be a large number that

Suprise!

malloc() allocates from the current segment. (64k)
farmalloc() allocates from all conventional memory (640k)

YOU are left with the very *FUN* job of allocating and using
extended/expanded memory.

Look for a library to do this or get a dos extender (like Phar Lap) to
eliminate all this segment nonsense.

----
The Ferret Bulletin Board System (501) 791-0124
North Little Rock, Arkansas
Carrying RIME, Throbnet, UN'I, and Usenet

Tim Fagan

unread,
Nov 28, 1994, 12:06:14 PM11/28/94
to
In article <3b0i4o$m...@nntp.Stanford.EDU> tre...@leland.Stanford.EDU (John Alfred Trezza) writes:
>From: tre...@leland.Stanford.EDU (John Alfred Trezza)
>Subject: URGENT TURBO C++ MEMORY QUESTION
>Date: 23 Nov 1994 23:10:16 GMT

>I am posting this for a friend...
>Please either respond in the newsgroup or to the e-mail
>address at the end of this message. THANKS A LOT FOR THE
>HELP. THIS IS A FAIRLY URGENT QUESTION for a program being
>written at home. ANY ADVICE WOULD BE MOST WELCOME!!
>Again, either respond in the newsgroup,
>or, (better yet) to the e-mail address at the end of the post.
>You can also send e-mail to me, the poster, if you like.
> --john trezza


>In general, the problem deals with using extended memory in Turbo C++

To use ems or xms you need to use intterupts 0x67. This is not difficult but
you have to do it right. A good explanation and source of example code can be
found in "PC Intern" by Micheal Tischer

good luck

Tim


Eric or Dana Jorgensen

unread,
Nov 30, 1994, 7:24:58 AM11/30/94
to tre...@leland.stanford.edu
John Alfred Trezza (tre...@leland.Stanford.EDU) wrote:
:> In general, the problem deals with using extended memory in Turbo C++


:> Specifically, here is a bit of code that I can't get running
:>
:> Here's the program:
:> /* main.c */
:> #include <stdio.h>
:> #include <dos.h>
:> #include <alloc.h>
:>
:> int main(int argc,char *argv[])
:> {
:> char huge *buffer;
:> unsigned long size;
:>
:> size = 600*800; /* pick some very large size */
:> buffer = (char huge *)farmalloc(size);

There are several problems here:

1) the huge keyword means tat you can allocate more than 64K, but it
still can onlly be in conventionall memory.

2) farmolloc can't allocat EMS memory

3) Even if you were allocating EMS memory correctly, you should know that
the IDE is a memory hog and will not let you access any extended or
expanded memory from your program. So you must use a debugger or run
your programs from the DOS prompt to use the extra memory.

You can get the code for the EMS example by calling Borland's TechFaxx
line or from the Borland BBS:

TechFax: 800-822-4269
BBS: 403-439-9096

I hope this is useful info.

-e

Christopher Benson

unread,
Dec 2, 1994, 3:27:10 AM12/2/94
to
: In article <3b0i4o$m...@nntp.Stanford.EDU>,

: tre...@leland.Stanford.EDU (John Alfred Trezza) wrote:
: <
: < *The Problem*
: < How do I use extended memory and allocate sizes that are large (say 1 Meg) ?
: <
: < Turbo C has a program called EMSTEST and I ran that and it executed ok, so I
: < assume that it can be done (i.e. I'm doing something wrong).
: <
: < What am I doing wrong? Is there some compiler option I've missed? A header
: < file? A library? Bad Code?!!! Keep in mind that I come from Unixland where
: < there is no farmalloc and I don't have to deal with segmented memory...
: <

I have a Turbo C/C++ library that encapsulates the required software

interrupts to allocate XMS memory, but they don't (and cannot) return a
pointer or far pointer. They return a 32 bit unsigned long *handle*, and
should be used by the application to access pieces of a large XMS chunk
with a reference to the handle and a (possibly 32 bit ulong) offset.

I will post the library as a uuencoded ZIP file within the next 48 hours.
It is a freeware library that I obtained but contains the *usual* complete
distribution set restrictions. That is why it will take me 48 hrs.

P.S. It works, I have used it to go beyond my usual farmalloc()
limitation of about 560kb.

Chris Benson.


Reggie Nolan Burnett

unread,
Dec 2, 1994, 9:59:07 PM12/2/94
to
sh...@sugar.demon.co.uk (shaun bellingham) writes:

>switches memory pages in and out of (emulated) expanded memory).To directly
>access extended memory requires switching into protected mode (no direct access
>to > 1Mb is possible with a processor in real mode) which is a bit more of a tin

Well, that is not quite true. I debated whether to post since I can't
remember all that I need to about it, but figured some info is better
than none. There is an undocumented opcode than was in the 286 and 386.
Be sure to check if it is in the 486 and Pentium. It is the LOADALL
instruction. You will have to code a macro that uses the hex numeric for
it since assemblers will not assemble it. Using that opcode you can from
real mode insert values into all the registers on the chip. What this
means is that the selector start and limit values can be set. Once this
is done, a program can read from extended memory without going into
protected mode. Dr. Dobb's Journal published an article, probably 1.5 -
2 years ago, describing a diskcopy program that used the technique to
access lots of memory from real mode to provide one-pass copying.

I know you are now shaking your head, saying I am not going to do that.
So many times there are people that say you can't do something, or have
to do it this way or else and very often they are wrong. I just wanted
to point out that, yet again, there is another way.

See ya.

Reggie

0 new messages