🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #1474

Re: BC++ Far new()

#1474
From: Jamshid Afshar
Date: Thu, 10 Sep 1992 19:44
39 lines
2450 bytes
In article <18j1t9INNbs3@usenet.INS.CWRU.Edu> bu254@cleveland.Freenet.Edu (Stephen Groundwater) writes:
>>Question : how can I call the far version of 'new()' from a small memory
>>           program ?
>
>char far* MyBuf;
>MyBuf=(char far *)new[100L];
>Voila, 100 bytes of far memory, the important bit is the L.

When I first saw this I thought it contained a syntax error because
you didn't specify the type (eg, "new int[100L]").  I'm still not sure
whether its legal but BC++ 3.1 does accept it.  The code is still
wrong, though, because BC++ assumes you're allocating 100 'int's.  The
fact that you had to cast should have tipped you off that something is
wrong with the code.  Unlike malloc(), 'new' always returns a pointer
of the correct type.
	char far* MyBuf = new char[100L]
	// calls 'void far* operator new(unsigned long)' in all memory models

I would recommend using a different, more explicit syntax, though:
	char far* MyBuf = new far char[100];
	// calls 'void far* operator new(unsigned long)' in small&medium,
	// calls 'void* operator new(size_t/*unsigned int*/)' in large&huge
	//   (pointers/heap are 'far' in compact, large and huge models) */

You can also use this syntax to allocate 'huge' objects (objects over
64K requiring 'huge' pointers):
	char huge* MyBuf = new huge char[80000];
	// always calls 'void far* operator new(unsigned long)'

Remember, though, that anytime you use the 'far' or 'huge' keywords,
you're using a non-portable (even to other MS-DOS compilers) syntax,
and that it isn't thoroughly documented (actually, I don't think this
'new' stuff is documented at all).  Compile with and heed all
warnings, and make sure you know what you're doing if you put in a
cast.  Also, BC++ 3.1 users, make sure you have the 'operator new()'
patches in BC31P1.ZIP from Simtel's BORLANDC directory.

Jamshid Afshar
jamshid@emx.utexas.edu
Technical Details
Message-ID: <79483@ut-emx.uucp>
Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!sdd.hp.com!cs.utexas.edu!ut-emx!jamshid
References: <18j0e6INN8ju@usenet.INS.CWRU.Edu> <gin503.715957220@cdc835> <18j1t9INNbs3@usenet.INS.CWRU.Edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!sdd.hp.com!cs.utexas.edu!ut-emx!jamshid
From: jamshid@ut-emx.uucp (Jamshid Afshar)
Newsgroups: comp.os.msdos.programmer
Subject: Re: BC++ Far new()
Summary: if you need to cast, it's probably wrong; "new far char[100]"
Message-ID: <79483@ut-emx.uucp>
Date: 10 Sep 92 19:44:06 GMT
References: <18j0e6INN8ju@usenet.INS.CWRU.Edu> <gin503.715957220@cdc835> <18j1t9INNbs3@usenet.INS.CWRU.Edu>
Reply-To: jamshid@emx.utexas.edu
Organization: The University of Texas at Austin; Austin, Texas
Lines: 39