users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dl_malloc


From: Daniel Diaz
Subject: Re: dl_malloc
Date: Fri, 13 Oct 2000 16:34:32 +0200

Hello Edmund,

The reason to not use the initial malloc is because it uses MMAP for big bloc 
allocations and the MMAP adresses returned are not compatible with gprolog 
address space (3 most significant bits should be 0).

Here is a little prolog program that should test if malloc is OK

t(N):- 
        retractall(p(_)),
        l(N,L), 
        assertz(p(L)),
        p(L1),
        (length(L1,N) -> write(ok) ; write(fail)),
        nl.

l(0,[]) :- !.

l(I,[a|L]):-
        I1 is I-1,
        l(I1,L).

to test:

try:

t(20000).

with the original malloc I have a 'Fatal Error: Segmentation Violation'
while it is OK with the used version.

Here is a C program that tests from which required size malloc uses MMAP:

#include <stdio.h>
#include <stdlib.h>

main()
{
  int i = 0;
  long p;
 

 
  for(;;)
    {
      p = (long) malloc(i*1024);
      if (p == 0)
        {
          printf("fault with at %d Kb\n", i);
          break;
        }
      if (p & 0xe0000000)
        {
          printf("invalid address for %d Kb (addr = 0x%lx)\n", i, p);
          break;
        }
      i++;
    }
}

compile with gcc -o x x.c
to run: ./x
On my machine I obtain:
invalid address for 128 Kb (addr = 0x40104008)
meaning that from 128 Kb malloc uses MMAP

My machine: Linux lima.univ-paris1.fr 2.2.15-4mdk #1 Wed May 10 15:31:30 CEST 
2000 i686 unknown

So I think your version is broken (except if you never do assertz, 
consult,... ie. nothing dynamic).

Could you try to use my orignal dl_malloc renaming things to see if it is OK ?







-- 
===============================================
                 Daniel Diaz
University of Paris 1      INRIA Rocquencourt
   75013 Paris           78153 Le Chesnay Cedex
     FRANCE                     FRANCE
        email: address@hidden
===============================================



-- 
===============================================
                 Daniel Diaz
University of Paris 1      INRIA Rocquencourt
   75013 Paris           78153 Le Chesnay Cedex
     FRANCE                     FRANCE
        email: address@hidden
===============================================





reply via email to

[Prev in Thread] Current Thread [Next in Thread]