Date: Thu, 21 Aug 1997 11:15:07 +0300 (IDT) From: Eli Zaretskii To: Victor cc: djgpp AT delorie DOT com Subject: Re: [Q] wrapping functions with linker In-Reply-To: <5tg75j$sj3$1@newton.pacific.net.sg> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Thu, 21 Aug 1997, Victor wrote: > General Protection Fault at eip=1af61; flags=3056 > eax=00000025 ebx=0000000e ecx=fffe6ad1 edx=0001cc85 esi=0001cc2b > edi=00000123 ebp=00000123 esp=00003006 cs=a7 ds=af es=af fs=8f > gs=bf ss=33 error=0000 Is this under CWSDPMI? It seems like the traceback is from CWSDPMI, and the registers seem to indicate that the crash is inside the DPMI server, not your program (ss != ds). Your `malloc' replacement is not general enough, so it seems (e.g., `free' does nothing etc.), which might not be good enough for the startup code which calls `malloc' quite a lot. It seems to me that if you would to use `alloca', it would have been much easier. Since your allocations are all freed before a function exits, `alloca' is the best solution. And it won't have any adverse effects on the library. You only need to know how much stack you need at most, and set _stklen to that value. > The reason I'm using such a weird malloc() replacement is that I'm > doing a program which could be running for a long time (probably days) > and when I check available DPMI memory, it's going down all the time. > I understand that after calling free() memory is added to a free > memory pool, but the DPMI memory is going low at an alarming rate and > the memory in the pool gets fragmented too (and I don't have any > control over the memory in the pool). If the `alloca' solution isn't good enough, try the GNU malloc (it's under GPL). It is specifically tailored to such cases (it relocates large buffers to prevent fragmentation and minimize calls to `sbrk'). One place to look is on GNU ftp sites; if you have Emacs sources installed, look there for the files gmalloc.c and ralloc.c. Emacs uses `malloc' and `free' a lot, and it is also supposed to run for days (on Unix systems).