(Interfacing Prolog) pointer issue (SWI)



Hi All.
I am currently using SWI Prolog 5.6.x.
Note that I am not an expert C programmer.
I have the following C code (compiled into a dll):
-----------
#include <SWI-Prolog.h>
#include <stdlib.h>
#include <ctype.h>
foreign_t alloci(term_t address) {
int result = PL_unify_pointer(address, (void *)malloc(sizeof(int)));
return result;
}
-----------
This code is evidently completely unuseful, since it doesnt work as I
dreamt. In particular, after load_foreign_library/1 call, I try the
following:

?- alloci(P1), alloci(P2).
P1 = 1069858230
P2 = 1069858230

that is, space allocated by the first call is deallocated on exiting and
reallocated by the second call. Isnt it? In other word I am unable to
allocate memory that remains, lets say, allocated even in Prolog toplevel
(or whatever).
Does anyway to do this (if someone have understood my terrible explanation)
exist?
Thanks a lot.
/\/\


.