🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: alt.msdos.programmer
2 messages
2 total messages Started by Greg Flint Fri, 09 Feb 1990 06:15
Need help with Turbo C "farmalloc"
#1268
Author: Greg Flint
Date: Fri, 09 Feb 1990 06:15
27 lines
2084 bytes
I've been trying to use the "farmalloc" routine with Turbo C 2.0.  I am
trying to allocate numerous small units (e.g., 6 - 20 bytes with each
call).  I don't know the number or size of the units in advance -- it is
data dependent -- so I can't use "farcalloc".

The problem that I'm having is that when I request 1-8 bytes, I'm given
16.  When I request 9-16, I'm given 32 bytes...and so on.  This causes
me to run out of memory long before I should.  (This is determined by
calling "farcoreleft" after each "farmalloc" call.)

The manual says that I should get "n" bytes when I request "n" bytes, but
I seem to be getting memory in paragraphs -- and 2x what I think I'd need
even if it had to give them to me in 16 byte units.  I called Bourland
support -- what a waste of $'s that was -- and was told that "probably"
memory was given out in paragraphs and that "probably" it was supposed to
work that way -- regardless of what the manual says.  In short, I got no
info from Bourland.

Does anyone have a patch or a code around for this problem?  I know that I
could do one big "farmalloc" and write my own "little malloc", but speed
is important and I'd prefer not have to execute "C" code if assembler code
(or a patch) is available.  Besides, writing "little malloc" seems a lot
like re-inventing the wheel.
-------------------------------------------------------------------------------
Greg Flint 	  Math G-169   (317) 494-1787   UUCP:  purdue!klaatu.cc!afc
  Purdue Univ.	  Purdue University	    INTERNET:  afc@klaatu.cc.purdue.edu
  Computing Ctr.  West Lafayette, IN 47907    BITNET:  flint@purccvm.bitnet
Re: Need help with Turbo C "farmalloc"
#1270
Author: James Webster Birdsall
Date: Fri, 09 Feb 1990 18:10
31 lines
2377 bytes
In article <4100@mace.cc.purdue.edu> afc@mace.cc.purdue.edu (Greg Flint) writes:
>The problem that I'm having is that when I request 1-8 bytes, I'm given
>16.  When I request 9-16, I'm given 32 bytes...and so on.  This causes
>me to run out of memory long before I should.  (This is determined by
>calling "farcoreleft" after each "farmalloc" call.)
>-------------------------------------------------------------------------------
>Greg Flint 	  Math G-169   (317) 494-1787   UUCP:  purdue!klaatu.cc!afc
>  Purdue Univ.	  Purdue University	    INTERNET:  afc@klaatu.cc.purdue.edu
>  Computing Ctr.  West Lafayette, IN 47907    BITNET:  flint@purccvm.bitnet

   Since I'm not at my computer just now, I can't say for sure, but I
think that farmalloc is just an interface to the DOS memory-allocation
functions. These, of course, allocate memory in paragraphs. Since
several bytes at the beginning of every memory block are reserved for
system use, when you try for 9 bytes, it has to give you two
paragraphs, etc.
   Worse, there have been the occasional rumors about bugs in DOS's
memory handling functions, leading to system corruption if lots of small
blocks are allocated and released frequently.
   Things you could try: you could try switching to a larger memory
model (one with multiple data segments) and use malloc(). I've never
gotten malloc() to work right in larger memory models, but I've never
tried very hard.
   Otherwise I think you're going to have to write or find a library of
memory-management functions.


-- 
James W. Birdsall  jwbirdsa@phoenix.Princeton.EDU  jwbirdsa@pucc.BITNET
   ...allegra!princeton!phoenix!jwbirdsa   Compu$erve: 71261,1731
"For it is the doom of men that they forget." -- Merlin
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads