[DGD]string reference/swapout problems

Felix A. Croes felix at dworkin.nl
Fri Mar 5 20:33:54 CET 1999


Marc Spoorendonk <marc at freud.et.tudelft.nl> wrote:

>[...]
> I have attempted to code a really simple piece of code: A global errstr
> string which can be shown to the coder when a function returns an error
> state.
>
> What I want is:
> void set_errstr(string error_string);	// stores a string into the driver
> string get_errstr();			// retrieves the string
>
> Ofcourse this can be done with a str_new() but i thought that it should be
> possible to store just a pointer to the string in the driver. (see the
> paste of the source code) This works fine but when i force a swapout, the
> string gets swapped out and we get stuck with a string pointer which
> points into unknown space.
>
> My question is: Is there a way to prevent the string from being swapped
> out?

You can prevent swapping altogether in the config file by setting both
swap_fragment and static_chunk to 0, and masking swapout() in the
auto object.  That is the only way to prevent LPC datatypes, such as
strings, from being swapped out.


> And the general question: When do i need to str_ref() or str_del() when
> using strings in kfuns? 

str_ref(): whenever a pointer starts to point to a string.
str_del(): whenever a pointer that points to a string is assigned a
           new value, or becomes invalid.  In particular, if a
	   string is popped from the runtime stack, the pointer on
	   the stack becomes invalid and therefore str_del() has to
	   be used.

Regards,
Dworkin

List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list