15. Run-Time Memory Issues

15.஡ c   ६ 믮

**************************

**************************





This chapter answers questions which are related to DJGPP run-time memory allocation.

  ⢥砥  ,  易 DJGPP ।   ६ 믮.





15.1 How much virtual memory do you have?

15.1, ᪮쪮 㠫쭮   ?

=========================================

=========================================





Q: How much virtual memory can I use in DJGPP programs?

Q: 쪮 㠫쭮   ᯮ짮 ?





*A* :  That depends on the DPMI host you are using.  CWSDPMI (the free DPMI host which comes with DJGPP) will let you use all available conventional and extended memory (up to 128M) and up to 128M of disk space, for a grand total of 256M of virtual memory for your application.  Try a `malloc(50*1024*1024)' some day.

*A*:    DPMI ,   ᯮ. CWSDPMI (᢮ DPMI ,  室  DJGPP) ᪠  ᯮ짮  㯭 ⠭  ⥫  ( 128M)   128M ᪮ ࠭⢠,   饣 ⢠ 256M 㠫쭮   襣 ਫ. ஡ " malloc (50*1024*1024) ' .





With other DPMI hosts, your mileage may vary.  Quarterdeck's QDPMI, for instance, has a bug in some of its versions which effectively disables virtual memory under DJGPP (described in QDPMI VM bug in Section 15.3, below), so you only have whatever free physical RAM is left.  Under Windows 3.x, the amount of virtual memory you get depends on various virtual memory settings in the Control Panel and on the `.pif' file settings for the program you run (see Windows allocation subtleties in Section 15.5, below).  Under Windows 9x, the memory settings of the DOS Applications' Property Sheet define how much virtual memory a DJGPP program will get (see Win9x allocation details in Section 15.6, below).

 㣨 DPMI ࠬ,     . Quartdeck's DPMI , ਬ,  訡    ᨩ,  ⢨⥫쭮 ⪫砥 㠫   DJGPP (ᠭ  QDPMI VM 訡   15.3, ), ⠪   ⮫쪮 ,  ᢮ ⨢  㯭.  Windows 3x, ⢮ 㠫쭮 ,   砥,   ࠧ  ⠭ 㠫쭮    ࠢ   ⠭ ". Pif ' 䠩  ணࠬ   믮 (. ⮭ । Windows   15.5, ).  Windows 9x, ⠭   ᢮⢠ ਫ DOS ।, ᪮쪮 㠫쭮 ,  ணࠬ DJGPP  (. ஡ ।   15.6, ).





15.2 It seems `malloc'/`free' don't affect virtual memory...

15.2 ,  "malloc /free"    㠫  ...

============================================================

============================================================





**Q*: I did `malloc(50*1024*1024)', but didn't see any paging happen, and I only have 8 MBytes of RAM on my machine.  Is this virtual memory thing for real?*

** Q*:   " malloc (50*1024*1024) ',   ,   ⠭ 稫,   ⮫쪮  8      設.    㠫쭠  ॠ쭮? *





**Q*: I `malloc''ed a large chunk of memory, but when I check values returned by `_go32_remaining_physical_memory' or `__dpmi_get_memory_information', I don't see any change...*

** Q*:  "malloc" 让 ᮪ ,    ஢ 祭, 饭 "_go32_remaining_physical_memory"  " __ dpmi_get_memory_information ',      ...*





**Q*: When I `free' allocated RAM, `_go32_remaining_physical_memory' reports there was no change in the available RAM.*

** Q*:   "᢮" ।  , "_go32_remaining_physical_memory"       㯭  *





*A* :  CWSDPMI (and, possibly, other DPMI hosts) only pages in memory when it is actually accessed.  If you only `malloc' it, but don't actually access it, it won't grab those pages.  Try `calloc' and see the *big* difference.

*A*: CWSDPMI (, , 㣨 DPMI ) ⮫쪮 ࠭  ,    䠪᪨ . ᫨   ⮫쪮 "malloc", ⮣  䠪᪨  頥  ,   㤥 墠뢠  ࠭. ஡ "calloc",  㢨 *讥* ࠧ稥.





When you call `free', DJGPP library doesn't return memory to the system, it just adds it to its internal pool of free pages.  So, from the system point of view, these pages are not "free".

  뢠 "free", DJGPP ⥪  頥  ⥬,  ⮫쪮    ७  ᢮ ࠭. ,  窨 ७ ⥬,  ࠭  "᢮".





15.3 Failure to get more memory than is physically installed

15.3 祭 ⪠   襣 ⢠  祬 䨧᪨ ⠭

============================================================

============================================================





**Q*: When I try to access more memory than the free physical RAM, `malloc' returns a `NULL' pointer, or I get some cryptic error message like this:*

** Q*:   ஡   襬   祬 ᢮  , "malloc" 頥 "NULL" 㪠⥫,    ஥ 筮 ᮮ饭  訡  ⮬:*





DPMI: Not enough memory (0x00860000 bytes)

DPMI: Not enough memory (0x00860000 bytes)





*or like this:*

*  ⮬:*





QDPMI: Memory Paging Violation: Illegal Page Reference [PTE=0000-0000h] [CR2=8006-3000h at 00E7h:0000-4936h]

QDPMI: Memory Paging Violation: Illegal Page Reference [PTE=0000-0000h] [CR2=8006-3000h at 00E7h:0000-4936h]





QDPMI: Unrecoverable Exception: 000Eh at 00E7h:0000-4936h.  Error Code = 0006h

QDPMI: Unrecoverable Exception: 000Eh at 00E7h:0000-4936h.  Error Code = 0006h





*A* :  This is typical of Quarterdeck's DPMI host called QDPMI which comes with QEMM386 version 7.53 and earlier.  Some versions of QDPMI (those which come with QEMM v6.x) fail to resize memory blocks when the new size is more than the available physical RAM, even though virtual memory services are enabled; other versions (those which come with QEMM v7.x) just don't let you allocate more memory than is physically available.  If you must use more RAM than is physically available, disable or uninstall QDPMI in Section 12.2, and use CWSDPMI instead.

*A*:  ⨯筮  DPMI  Quarterdeck, 뢠 QDPMI,  室  QEMM386 ᨥ 7.53  ࠭.  ᨨ QDPMI (,  室  QEMM v6. x)    ﭨ  ࠧ  ,   ࠧ -  祬 㯭  ,   ⮬,  㠫 ࢨ  ᪠; 㣨 ᨨ (,  室  QEMM v7. x) ⮫쪮,  ᪠ ।  ⢮  祬,  䨧᪨ 㯥. ᫨  ᯮ짮 襥 ⢮   祬,  䨧᪨ 㯥, ⪫  ⠭ QDPMI   12.2,  ᯮ짮 CWSDPMI  .





This bug was corrected in QDPMI version 1.10 or later, distributed with QEMM beginning with version 8.0, so upgrading to the latest version of QEMM might also be a solution.  With QEMM 6.x, make sure your programs don't override the default type of `sbrk' behavior by setting `_crt0_startup_flags' to `_CRT0_FLAG_UNIX_SBRK' (QEMM 8.0 and later can allocate virtual memory with both types of `sbrk' algorithm).

 訡 뫠 ࠢ  QDPMI ᨨ 1.10  , ஭  QEMM, 稭  ᨥ 8.0, ⠪   ᫥ ᨨ QEMM   ⠪  襭.  QEMM 6. x, 㤮⮢,   ணࠬ  ⬥   㬮砭 ⨯ "sbrk" ,  ⠭ " _crt0_startup_flags'  " _CRT0_FLAG_UNIX_SBRK ' (QEMM 8.0    । 㠫    ⨯ " sbrk ' ).





If you use another DPMI host, make sure that virtual memory is enabled. E.g., for 386Max, include the `swapfile=' parameter to establish a virtual memory swap file; you can make it permanent (this will speed up DJGPP start-up) with the `/p' option.

᫨  ᯮ  DPMI , 㤮⮢,  㠫쭠  㯭. ਬ,  386Max,  " swapfile = ' ࠬ, ⮡ ⠭ 㠫 ᢮ 䠩 ;     ﭭ ( ᪮ DJGPP )  樥 /p.





15.4 Memory allocation fails before all memory is used ======================================================

15.4 ᡮ ।    ᥩ 



======================================================





**Q*: OK, I've changed my program to never allocate more memory than is physically available, to work around that QDPMI VM bug in Section 15.3, but my program still gets a `NULL' pointer from `malloc/calloc'!*

** Q*: ,    ணࠬ, ⮡   । 襥 ⢮  祬 䨧᪨ 㯭,  ⮣ ⮡ ࠡ  ⮩ QDPMI VM 訡   15.3,   ணࠬ   砥 "NULL" 㪠⥫  "malloc/calloc"! *





**Q*: Why is my program dying with SIGSEGV under CWSDPMI when allocating a chunk of memory?*

** Q*: 祬  ணࠬ 㬨ࠥ  SIGSEGV  CWSDPMI  । ᪠ ? *





*A* :  Another peculiarity of QDPMI which came with QEMM before version 8.0: it will never let you allocate a chunk which is larger than half of what's available.  The Windows 3.x behaves in the same way, and several people reported the same to be true under Windows 95.

*A*: 㣠 ᮡ QDPMI,  襫  QEMM । ᨥ 8.0:    㤥 ᪠ , । ᮪,   訬 祬,  祣 㯭.  Windows 3x  ᥡ ⠪  ࠧ,  ⤥  ᮮ騫,    ᠬ  ⨭  Windows 95.





With some DPMI providers, this behavior might be triggered by a small overhead of each `malloc' call: you might ask for half of available memory, but the DJGPP implementation of `malloc' adds the overhead and then rounds the amount of memory to the next power of 2 before calling `sbrk'; thus `malloc(8MB)' will actually request 16MBytes from the DPMI host.  When in doubt, call `sbrk' directly, especially if you don't plan to free that memory during execution.

 묨 DPMI ⠢騪,      맢 묨 ந⥫묨 ⠬  饭 "malloc":      㯭 ,  DJGPP ॠ "malloc"  ᢮   ⥬ 㣫 ꥬ   祭 襭  㬭  2 । 맮 "sbrk"; ⠪ ࠧ " malloc (8) ' 䠪᪨  16MBytes  DPMI .   ᮬ, 맮 "sbrk" ।⢥, ᮡ, ᫨    ᢮    祭 믮.





If your program asks for memory in lots of small allocations, then it might crash when you use CWSDPMI as your DPMI host.  This is because CWSDPMI runs out of its tables where it tracks memory allocations.  If you use release 1 of CWSDPMI, you can enlarge the maximum space that CWSDPMI uses if you get a CWSDPMI heap-fix patch, e.g. ftp://ftp.neosoft.com/pub/users/s/sandmann/csdpmi1heapfix.zip.  Beginning with release 2, CWSDPMI defines a larger (6KB) default heap that is configurable by CWSPARAM program to be anywhere between 3K and 40K bytes, without recompiling CWSDPMI.  You should upgrade to the latest CWSDPMI if you experience such problems.

᫨  ணࠬ 訢   讬 ⢥  ᪮,    ਢ  ,   ᯮ CWSDPMI   DPMI .  - , ⮬  CWSDPMI 믮  ⠡,   ᫥ । . ᫨  ᯮ  1 CWSDPMI,   㢥稢 ᨬ쭮 ࠭⢮, ஥ CWSDPMI ᯮ,   CWSDPMI  ࠧ , ਬ ftp: // ftp.neosoft.com/pub/users/s/sandmann/cs dpmi1heapfix.zip. 稭  ᪠ 2, CWSDPMI ।  ( 6 )  㬮砭 ,      3  40  ⮣, ⮡ ࠭᫨஢ CWSDPMI.     ᫥ CWSDPMI, ᫨  뢠 ⠪ ஡.





15.5 Memory allocation fails under Windows

15.5 ।  ௨ 㤠  Windows

==========================================

==========================================





**Q*: I'm running under Windows 3.x DOS box, but DJGPP complains about there not being enough DPMI memory, although virtual memory is enabled.*

** Q*:  믮   Windows 3   DOS,  DJGPP  ⭮⥫쭮 筮 DPMI ,  㠫쭠  ᪠ *





*A* :  You must make sure the size of your Windows swap file can be at least 2 times the largest virtual memory size you need.  Check if you have enough free disk space; if you do, run a defragger (Windows needs the swap file to be contiguous).  This size is normally limited by the the "virtual = 4 times free physical" rule, but you can change that by inserting the line

*A*:   㤮⮢,   ࠧ 襣 ᢮ 䠩 Windows    ࠩ  2 ࠧ ,  祬 ᠬ  㠫쭠   ன  㦤. ஢,    筮 ᢮ ᪮ ࠭⢮; ᫨  , 믮 defragger (Windows 㦤  ᢮ 䠩  뢭).  ࠧ 筮 ࠭稢 " 㠫 = 4 ࠧ  祬 䨧᪨ "  ࠢ,     ,  ⠢  ᮮ⢥ ப:





PageOverCommit=n

PageOverCommit=n





in the `[386Enh]' section of your `SYSTEM.INI' file.  The parameter `n' is 4 by default, but can be set to be as large as 20.

 " [386Enh] ' ࠧ 襣 "SYSTEM.INI" 䠩. ࠬ "n" = 4  㬮砭,    ⠭, ⮡  ⠪ ࠧ,  20.





15.6 Memory allocation peculiarities under Windows 9x

15.6 ᮡ ।   Windows 9x

=====================================================

=====================================================





**Q*: I seem to be unable to get more than 16 MBytes of virtual memory under Windows 95, even though I have 32 MBytes of RAM installed on my machine, and a lot of disk space...*

** Q*:    ᯮᮡ   祬 16  㠫쭮   Windows 95,   ⮬,    32 , ⠭   設,   ᪮ ࠭⢠ ...*





*A* :  You must set the maximum amount of DPMI memory to 65535K in the DOS applications' property sheet.  If you leave that setting at the default "Auto", you only get 16 MBytes.  You must actually type 65535 inside the dialog box, as checking out the values from the list Windows offers will never get you past 16384 (i.e., 16MB).

*A*:   ⠭ ᨬ쭮 ⢮ DPMI  65535  ᢮⢠ ਫ DOS. ᫨  ⠢  ⠭  "" 祭  㬮砭,  ⮫쪮 砥 16 .   䠪᪨  65535   , ⠪  ஢ઠ 祭  ᯨ᪠, । Windows      諮 16384 ( , 16).





Note that you cannot allocate more than half the available memory in one chunk under Windows 9x, exactly as the things are under Win3.x, and you cannot have more than 64 MBytes of virtual memory available to DJGPP programs running on Windows.

 ,     ।  祬  㯭    ᪥  Windows 9x, 筮 ⠪     Win3. x,       祬 64  㠫쭮   㯭 ணࠬ DJGPP, 믮饩  Windows.





15.7 Memory allocation fails under EMM386 or HIMEM

15.7 ।  ௨ 㤠  EMM386  HIMEM

==================================================

==================================================





**Q*: My machine has 48 MBytes of RAM, but when I run DJGPP programs, they start paging after 32 MBytes have been used...*

** Q*:  設  48 ,    ᪠ ணࠬ DJGPP,  稭  ᫥ ⮣,  32  ᯮ짮 ...*





**Q*: I have 5 MBytes of free RAM on my machine, but DJGPP programs start paging after only 256KBytes of memory were used??*

** Q*:   5  ᢮   設 ,  DJGPP ணࠬ 稭 , ⮫쪮 ᫥ 256KBytes  ᯮ짮?? *





*A* :  This might be caused by some old versions of the memory manager installed in your machine (like HIMEM or EMM386 from an old version of DOS), which were limited to 32 MBytes of expanded memory.  Try running without them (CWSDPMI can use raw extended memory), or upgrade to a newer version of DOS.

*A*:     맢 묨 묨 ﬨ ᯥ , ⠭   設 ( HIMEM  EMM386  ன ᨨ DOS),  뫨 ࠭祭 32  (EMS) ७ . ஡ 믮   (CWSDPMI,  ᯮ짮 ࠡ⠭ (XMS) ⥫ ),  騢 ᫨⥫     ᨨ DOS.





If your programs start paging after only 256KBytes of memory were used, most probably you are using EMM386 and CWSDPMI, and your `CONFIG.SYS' specifies no amount of memory when it installs EMM386.  EMM386 defaults to 256K in this case; you should tell EMM386 explicitly how much memory it should take over. You can use the `go32-v2' program to see what amount of extended memory your DJGPP programs will get.  

᫨  ணࠬ 稭 , ᫥ ⮫쪮 256KBytes  ᯮ짮,    ᯮ EMM386  CWSDPMI,   " CONFIG.SYS'  ।  ꥬ ,   ⠭ EMM386. EMM386 祭  㬮砭  256  ⮬ 砥;   ᮮ EMM386 , ᪮쪮    ਭ.   ᯮ짮 ணࠬ `GO32-V2 ' ணࠬ  ⮣ ⮡ ᬮ  ⢮ ७    ᯮ짮.





15.8 How much memory do parent DJGPP programs leave for their child?

15.8, C쪮  ⡨ࠥ  ணࠬ DJGPP த⥫  ᪠ ୨ ?

====================================================================

====================================================================





**Q*: How much memory is available when I call the `system' library function?*

** Q*: 쪮  㯭,   뢠  㭪 "system"? *





*A* :  In the conventional (below 640K mark) memory, you are left with everything which was free before your program started, except what the DPMI host uses.  The amount of conventional memory required by the DPMI host depends heavily on the host you use.  For the first DJGPP program, QDPMI uses about 97K, CWSDPMI uses about 70K, Windows 3.x only 18 KBytes.  Each subsidiary call to `system' (like in recursive invocation of `Make') eats up about 18K (16K for the transfer buffer and 2K for the PSP and environment) for most DPMI servers; a notable exception is QDPMI which needs 97K bytes of low memory for the subsequent calls too.  If you change the size of the transfer buffer (with `STUBEDIT'), the amount of free conventional RAM will change accordingly.

*A*:  ⠭⭮ ( ⪨ 640) ,  㯭 ,  뫮 ᢮ । ᪮ 襩 ணࠬ,  ᪫祭  ᯮ DPMI ஬. ⢮ ⠭⭮ , ॡ㥬 DPMI ஬   ⥯ ᯮ짮  .  ࢮ ணࠬ DJGPP, QDPMI ᯮ  97, CWSDPMI ᯮ ⭮⥫쭮 70, Windows 3x ⮫쪮 18 .  ᯮ⥫쭮 饭  "system" (  ४ᨢ 맮 "make") ࠥ  18 (16   ।  2  PSP  㦥 )  設⢠ DPMI ࢥ஢; ⭮ ᪫祭 - QDPMI,  㦤   97    ᫥ 맮 ⠪. ᫨   ࠧ  । ( "STUBEDIT"), ⢮ ᢮ ⠭⭮ RAM  ᮮ⢥⢥.





Extended memory management is left to the DPMI server; DJGPP does nothing special about XMS when `system' is called.  This means that all the extended memory used by the parent program is *not* freed when the child program starts; if the child requests more memory than is physically free, the DPMI server is expected to page some of the parent out to honor the request. (This is unlike DJGPP v1.x, where the `go32' extender would completely page out the parent before starting the child.)  The advantage of this is that spawning a child or shelling out is much faster in v2 than it used to be with v1.x, except on machines with low amounts of installed RAM.  A disadvantage is that if you spawn a real-mode program that uses XMS, the extended memory used up by your DJGPP program will be unavailable to it, unless you use a memory manager (as opposed to when CWSDPMI uses raw XMS or HIMEM).  The only way around this problem is to buy more RAM, or to install a real memory manager.

 (XMS) ⥫쭮  ⠢ DPMI ࢥ஬; DJGPP   祣 ᯥ樠쭮 ⭮⥫쭮 XMS,  "system" 뢠.  砥   (XMS) ⥫쭠 , ᯮ㥬 த⥫᪮ ணࠬ - ** ᢮,   ணࠬ ; ᫨ ୨  ॡ 襣 ⢠  祬  䨧᪨ ᢮, DPMI ࢥ,  ࠭  த⥫. (  ⫨稥  DJGPP v1. x,  "go32" ⥫    ࠭ ᭠㦨 த⥫ । ⮬ ୥.) २⢮ ⮣ 室  ⮬,  ஦ ୥     ᭠㦨   ॥  v2 祬  v1. x,  ᪫祭  設   ⢠ ⠭  . ⮪ , , ᫨  ஦ ணࠬ ॠ쭮 ०,  ᯮ XMS, XMS ᯮ짮 襩 ணࠬ DJGPP 㤥 㯭  , ᫨   ᯮ ᯥ  ( ⨢ ⮬,  CWSDPMI ᯮ ।⢥ XMS  HIMEM). ⢥ ᯮᮡ   ஡ ⮨  ⮬, ⮡ 㯠 襥 ⢮  ,  ⠭ ॠ쭮 ᯥ .





Note that if you use a memory manager such as EMM386 or QEMM386 with the NOEMS parameter, CWSDPMI will use the XMS (as opposed to VCPI) services to allocate extended memory, and will allocate all of the available XMS memory for itself.  So if, while your DJGPP program runs, some resident software such as device driver or TSR will try to allocate XMS, the allocation will fail.

  , ᫨  ᯮ ᯥ  ⨯ EMM386  QEMM386  ࠬ஬ NOEMS, CWSDPMI ᯮ XMS ( ⨢ VCPI) 㣨, ⮡ । (XMS) ⥫ ,  ।  㯭 XMS   ᥡ.  ᫨,   ६   ணࠬ DJGPP 믮, ஥ १⭮ ணࠬ ᯥ祭 ⨯ ࠩ ன⢠  TSR ஡ । XMS, । 㤥 ௥ 㤠.





15.9 How much stack can I have in DJGPP programs?

15.9, ᪮쪮 ⥪     ணࠬ DJGPP?

=================================================

=================================================





**Q*: My program bombs when I use very large automatic arrays.*

** Q*:  ணࠬ    ᯮ 祭 訥 ⮬᪨ ᨢ. *





**Q*: How much stack space do I have in my program?*

** Q*: 쪮 ࠭⢮ ⥪      ணࠬ? *





**Q*: My program seems to overflow the stack, but only when I run it under a debugger...*

** Q*:  ணࠬ   ९ ⥪,  ⮫쪮,   믮   ⫠稪 ...*





**Q*: My program crashes with SIGSEGV, but the traceback makes no sense: it points to something called ___djgpp_exception_table...  When I try to debug this, the traceback mysteriously changes to some innocent library function, like getc().  The same program works flawlessly when compiled with DJGPP v1.x What is going on??*

** Q*:  ணࠬ ᡮ  SIGSEGV,  ⫠ 窨   ᫠:  窨  뢠 ___ djgpp_exception_table ...,   ஡ ⫠,   筮      㭪,  getc ().   ᠬ ணࠬ ࠡ⠥ 筮    DJGPP v1. x,  ந室?? *





*A* : DJGPP v2 programs get fixed-size stack which is allocated by the startup code and then stays fixed for the entire lifetime of the program; this is a bug/feature of the DPMI 0.9 specification.  By default, you have a 256KB-long stack, but some programs which use large automatic arrays, or are deeply recursive, might need more.  If the default stack size is not enough, you can change it with the `STUBEDIT' program (change the parameter "Minimum amount of stack space"), or by setting the global variable `_stklen' in your program.  Example:

*A* ணࠬ DJGPP v2  ⥪ 䨪஢ ࠧ,  ।  ᪠ (startup)  ⥬ ⠥ 䨪஢  祭 ᥣ ப ࠡ ணࠬ;  訡 / ⥫ DPMI 0.9 ᯥ䨪樨.  㬮砭,   256KB ⥪,   ணࠬ,  ᯮ 訥 ⮬᪨ ᨢ,  㡮 ४ᨢ,   㦤 . ᫨   㬮砭 ࠧ ⥪  祭,     ணࠬ STUBEDIT ( ࠬ " 쭮 ⢮ ࠭⢠ ⥪ "),   ⠭ 쭮 ६ "_stklen"  襩 ணࠬ. ਬ:





unsigned _stklen = 1048576;  /* need a 1MB stack */

unsigned _stklen = 1048576;  /* need a 1MB stack */





The DJGPP startup code checks both the value in the stub info and the value of `_stklen', and uses the larger of these two.  Therefore, programs that are known to require large stack size should set `_stklen' to make sure they will always work, even if somebody stub-edits them to a lower value.  This technique is also safer when you need to debug your program with `gdb' (see below).  However, you might need to use `STUBEDIT' with programs for which you don't have the sources.

  ᪠ DJGPP ஢ 祭  誥  祭 "_stklen",  ᯮ 訥   . ⥫쭮, ணࠬ,   ⥭ ࠧ ⥪,  ⠭ "_stklen", ⮡ 㤮⮢,    ᥣ ࠡ,  ᫨  -  ।   誨    祭.  ⮤ ⠪  ,    ⫠  ணࠬ  "gdb" (. ). ,   㦤 ⮡ ᯮ짮 "STUBEDIT"  ணࠬ,      室.





Programs which need an unusually large stack might crash with bogus stack traces, because part of the heap gets overwritten by the overflowing stack. To see if that is the cause of such crashes, run `STUBEDIT' on your program and crank up the stack size to a large value (like 4MBytes).  If that makes the problem go away, tune the stack limit to the minimum value your program can live with, then set `_stklen' to an appropriate value as explained above and recompile the program.  (Some DPMI hosts will actually allocate the entire stack, even if not all of it is used, so leaving it at unnecessarily large value will hurt the program on low-memory machines.)

ணࠬ,  㦤  筮 讬 ⥪,   ࠧ  묨 ᫥ ⥪, ⮬    ⠭ ᠭ  ९騬 ⥪. ⮡ ,   稭 ⠪ ᡮ, 믮 "STUBEDIT"  襩 ணࠬ   訬 ࠧ஬ ⥪ ( 4MBytes). ᫨  ᮧ ஡, 室, ࠨ ࠭祭 ⥪  , 業  ணࠬ,      ⨬, ⮣ ⠭ "_stklen"  ᮮ⢥饬 祭  ᭥   ࠭᫨ ணࠬ. ( DPMI  䠪᪨ ।  ⥪,  ᫨    ⮣ ᯮ, ⠪ ⠢ ⮣  譥 讬 祭 稭 । ணࠬ  設  .)





Some users have reported that they needed to enlarge the stack size of the C++ compiler, `cc1plus.exe', to prevent it from crashing when compiling some exceedingly large and complex C++ programs.  Another program that was reported to need a stack larger than the default is `bccbgi.exe' from the `BCC2GRX' package.

 짮⥫ ᮮ騫,   㦤, ⮡ 㢥 ࠧ ⥪  C++, " cc1plus. exe ', ।   ਨ  ஢  १砩 訥  ᫮ ணࠬ C++. 㣠 ணࠬ  ,  ᮮ頫,  㦤  ⥪  祬 祭  㬮砭 - "bccbgi.exe"  "BCC2GRX" .





After you've used `STUBEDIT' to change the stack size, run it again to make sure it displays as default the value you thought you entered.  This is because `STUBEDIT' will sometimes silently set the stack size to 0 (and then you will get the default 256K stack) if it doesn't like the value you type (e.g. if it has a wrong syntax).

᫥ ⮣,   ᯮ짮 "STUBEDIT" ⮡  ࠧ ⥪, 믮  ᭮, ⮡ 㤮⮢,   ⮡ࠦ  祭  㬮砭 祭,  㬠,   .  ⮬  "STUBEDIT" 㤥   ⠭ ࠧ ⥪  0 ( ⥬     㬮砭 ⥪ 256) ᫨   室  祭,  ⠥ (ਬ, ᫨   ࠢ ᨭ⠪).





When you run a program as an un-stubbed COFF image under a debugger, the stack size comes from the debugger.  So if your program needs a large stack and you run it under `gdb', be sure to stubedit `gdb' to enlarge its stack to at least the value your program needs to run safely.

  믮 ணࠬ   誨 COFF ⮡ࠦ  ⫠稪, ࠧ ⥪   ⫠稪. , ᫨  ணࠬ 㦤  讬 ⥪   믮   "gdb", 㡥  stubedit "gdb",  㢥稫 ⥪   ࠩ  祭,  ணࠬ  믮 ᭮.





Under Windows, be sure you've allocated a sufficiently large swap file (let's say, 40MBytes) from the Windows' Control Panel, and make sure the `.PIF' file for your program doesn't have too low limit on EMS/XMS usage (better make them both -1).  What's that?  You don't have a `.PIF' file for this program?Then Windows uses the default file `DOSPRMPT.PIF', which almost surely defines very low limits on these two, and your program might have problems getting the memory it needs for its stack.

 Windows, 㡥,   । 筮 让 ᢮ 䠩 (᪠ 40MBytes)   ࠢ  㤮⮢ ". PIF ' 䠩  襩 ணࠬ   ᫨誮  ࠭祭 EMS/XMS ᯮ짮 (    -1).   ⨬?    ". PIF ' 䠩  ⮩ ணࠬ? ⥬ Windows ᯮ   㬮砭 䠩 "DOSPRMPT.PIF",   ᮬ । 祭  ࠭祭  ,  襩 ணࠬ,    ஡  祭 ,  ॡ  ⥪.





DJGPP v2.0 has a subtle bug in its startup code that is seen very rarely, and that manifests itself by a program crashing with Page Fault or SIGSEGV.  If you are using v2.0 and enlarging the stack and the CWSDPMI heap size didn't help, try adding some (e.g., 4KB) static data to your program and see if that helps.  But the best way to overcome this is to upgrade to DJGPP v2.01 or later.

DJGPP v2. 0  ⮭ 訡   ᪠,  祭 祭 ।,     ணࠬ, 饩   Page Fault  SIGSEGV. ᫨  ᯮ v2. 0   ⥪,  CWSDPMI ࠧ   , ஡   (ਬ, 4) ᪨   襩 ணࠬ,  .,   .  ᠬ 訩 ᯮᮡ ८  ⮨  ⮬, ⮡  ᫨⥫  DJGPP v2. 01  .







brk



===







⠪



-----







#include <stdlib.h>







int brk(void *ptr);







ᠭ



----------







 㭪  * 뢠(break) *  ணࠬ.  -  , , ᫨ 맢, ⠢ ࠢ ந室. ணࠬ   襬 ⢥ ,  । 訥 祭  PTR. 筮,  믮 祢 १ 㭪 malloc.







頥 祭



-----------







, ᫨ 뢠 뫮 , -1 ᫨ . ERRNO ⠭  訡.







ਬ



------







if (brk(old_brk+1000)) printf("no memory\n");







sbrk



====







Syntax



-----







#include <unistd.h>







void *sbrk(int delta)







Description



----------







 㭪  "뢠(break)" ணࠬ,     ⮬.  - ᠬ ᮪ ,   ணࠬ    ⮣, ⮡ 맢 襭.    -   뢠,     ( "malloc" 砥  ) 㢥稢 뢠.







 ⮩ 㭪樨 筮  ⮫쪮  "malloc" (malloc.).







頥 祭



-----------







 ࢮ   ।饣 ⨬ ᭮ ࢠ,  -1, ᫨     뫮  . 㣨 ᫮, 㪠⥫  ᮪ ,   ⮫쪮 ।, ᫨  । ⥫ .







Example



------







char *buf; buf = sbrk(1000); /* allocate space */

















