TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Michael Duffy
from: Jonathan de Boyne Pollard
date: 1994-11-07 05:01:28
subject: intelligent memory alloc

ZZ>
  >    Ok, so what exactly is the most intelligent way to allocate memory if yo
  > don't know exactly what you requirements will be?  Apparently malloc isn't
  > giving me any single allocations larger than 32K (Watcom v.10.0),
ZZ>

  I'd complain, or use the 32-bit compiler.  (-:

  malloc() and ::operator new are both be able to allocate enormous
  amounts of memory.

ZZ>
  > that I have to use DosAllocateMem, assign this memory with DosSubSetMem,
  > and then allocate it with DosSubAllocMem.
ZZ>

  This is useful for special purpose allocators (in C++), but for more
  general use I'd stick to malloc() if I were you.

ZZ>
  >                                         Should you just pick a goodly large
  > number (say, 100Meg) leaving the memory uncommitted till you need it, then
  > grow the suballoced heap?
ZZ>

  For what it's worth, malloc() in Borland C++ allocates the heap in
  multiples of 4Mb using DosAllocMem and uses DosSetMem to commit pages
  as needed.

ZZ>
  >    Do you handle memory differently depending on the application?
ZZ>

  As I said above, you can always use special-purpose allocators in C++
  by overriding operator new and operator delete. These are useful if
  you are working with data structures that are multiples of (or factors
  of) the page size, since you can dispense with some of the generality
  of malloc() to create a faster allocator.

  This only applies to a small number of data structures, however.  With
  a string class, for example, where the data are going to be of
  arbitrary length, and page alignment isn't important to performance,
  you would be better off sticking with the general purpose allocator
  provided in the run-time library.

  > JdeBP <
___
 X MegaMail 2.10 #0:

--- Maximus/2 2.02

* Origin: DoNoR/2,Woking UK (0483-725167) (2:440/4)
SEEN-BY: 12/2442 54/54 620/243 624/50 632/348 640/820 690/660 711/409 410 413
SEEN-BY: 711/430 807 808 809 934 942 949 712/353 623 713/888 800/1
@PATH: 440/4 141/209 270/101 396/1 3615/50 229/2 12/2442 711/409 54/54
@PATH: 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.