users-prolog
[Top][All Lists]
Advanced

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

memory allocation problem in external predicates


From: Erick Alphonse
Subject: memory allocation problem in external predicates
Date: Sat, 13 Jan 2001 15:29:19 -0500

Hello,

Allocation memories in my program fail when it is linked with a gprolog
object file.
Please, could you explain me what is the reason and if there is a way to
deal with it?

I'm using a modified version of gprolog 1.2.1 which no longer overrides
malloc,  setting M_MMAP_MAX to 0 (the reason is the newer versions of
gprolog are unstable with my program which crashes at the very top
level).

I use the linux-mandrake 7.2 on an i686 with 256M of RAM and 512M of
swap. the library gmp stands for GNU Multiple Precision Arithmetic
Library. GMP uses malloc, realloc and free for memory allocation. The
function 
void mpz_init_set_ui (mpz_t rop, unsigned long int op) 
initializes the struct rop, which represents an unbounded integer, and
set it to op.

Here we are the code used to examplify my problem:
test_alloc_gmp.c:

#include <gmp.h>

void test(void) {
  int i;
  mpz_t b;

  for(i=0;i!=10000000;i++)
    mpz_init_set_ui(b,-4);
}

main.pl:

:- initialization(top).
:- foreign(test,[return(none)]).

top :-
        test.

Runing a.out built with the command
gplc -L '-lgmp' test_alloc_gmp.c main.pl -o a.out 
outputs:
cannot allocate in gmp: Cannot allocate memory

If I link test_alloc_gmp.c with main.c written as follow:

void test(void);

int main() {
  test();
}

the program terminates successfully.

Please, I need help, feel free to ask me any piece of code which will
help for solving this problem.
Regards,
Erick Alphonse.



reply via email to

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