[mercury-users] Memory management when CPP calls Mercury

Ondrej Bojar oboj7042 at ss1000.ms.mff.cuni.cz
Thu Dec 13 23:20:42 AEDT 2001


Hi.

I intend to use my Mercury predicates in a C++ program. My predicates get
a string and return MR_list. I know, how to parse MR_list in C++, but I
don't understand what exactly does conservative garbage collector.

I'm afraid of not releasing memory occupied by the MR_list when done in C.
Proper releasing of memory is crucial for me, since the C++ program looks
like:

while (1) {
  char * a_new_thing;
  MR_list parsed_thing;

  a_new_thing = malloc_and_get_the_thing_from_somewhere();

  parsed_thing = my_mercury_function(a_new_thing);

  read_mr_list_and_dump_it_somewhere(parsed_thing);

  free(a_new_thing);

  /* should I release MR_list parsed_thing now? And how? */
}

I release the string with free(a_new_thing), but how do I release MR_list
parsed_thing? Or does this Mercury for me? When?

I need also the other way:

while (1) {
  int *input_array;
  MR_list input_list;
  char * parsed_thing;

  input_array = malloc_and_get_from_somewhere_a_list_of_numbers();

  input_list = use_MR_cons_to_build_MR_list_from_array(input_array);

  free(input_array);

  parsed_thing = my_mercury_function_to_parse_list(input_list);

  printf("Got: %s\n", parsed_thing);

  /* should I free parsed_thing now? (using free() I guess) */
}


Thanks for help, Andrew.


--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list