Mail Archives: djgpp/1996/07/24/11:14:48
Hi,
The following code fails with the line:
int _crt0_startup_flags = _CRT0_FLAG_LOCK_MEMORY;
but works otherwise: I get a segmentation fault in morecore (of libc malloc.c)
at the op->ov_next = 0; line of morecore, just before it exits.
This happens under csdpmi (v0.90 r2 and later). Windows hapilly allocates more
memory than I have, so I guess it does not know about CRT0_FLAG_LOCK at all!
I think the problem must be that the real memory runs out, but sbrk asks the
dpmi server to give it some more, and does not detect this (or the dpmi server
does not). So what sbrk really gets is virtual memory, but when you try to
access it, the dpmi server can't swap because all memory is locked.
Any solutions ? libc patches ?
Thanks in advance,
Sengan
Note to Snarfy: The DS theory did not work out: the problem was not in the
switching, but in malloc with locked memory!
--------------------------------------------------------------------------------
#include <crt0.h>
#include <stdio.h>
#include <conio.h>
int _crt0_startup_flags = _CRT0_FLAG_LOCK_MEMORY;
typedef struct space_wasting_struct {
struct space_wasting_struct *next;
char *space; } space_waster;
space_waster* wasted = NULL;
void main(void)
{ space_waster* tmp_sw;
char* tmp_space;
int n = 0;
while(!kbhit())
{
printf("PROC 2: allocated %dKb \n", n*64);
if ((tmp_sw = (space_waster *) malloc(sizeof(space_waster))) != NULL)
{ if ((tmp_space = (char *) malloc(64000)) != NULL)
{ tmp_sw->next = wasted;
tmp_sw->space = tmp_space;
wasted = tmp_sw;
n++; }
else
free(tmp_sw); }
}
getch();
while (wasted != NULL)
{ tmp_sw = wasted->next;
free(wasted->space);
free(wasted);
wasted = tmp_sw; }
}
- Raw text -