[plt-scheme] Memory management and MzScheme

From: Pedro Pinto (ppinto at cs.cmu.edu)
Date: Sun Nov 24 12:37:24 EST 2002

Ok!

Now I understand what you meant. That makes sense and is consistent with the
behavior I observed. I will adjust my code accordingly.

Thanks a lot,

-pp

----- Original Message -----
From: "Anton van Straaten" <anton at appsolutions.com>
To: "Pedro Pinto" <ppinto at cs.cmu.edu>; <plt-scheme at list.cs.brown.edu>
Sent: Saturday, November 23, 2002 8:13 PM
Subject: RE: [plt-scheme] Memory management and MzScheme


> A reference for this is Inside MzScheme:
> http://download.plt-scheme.org/doc/insidemz/insidemz.html
>
> In particular, Ch. 3, Memory Allocation:
> http://download.plt-scheme.org/doc/insidemz/insidemz-Z-H-3.html :
>
> "MzScheme uses both malloc and allocation functions provided the
> conservative garbage collector. Embedding/extension C/C++ code may use
> either allocation method, keeping in mind that pointers to
> garbage-collectable blocks in malloced memory are invisible (i.e., such
> pointers will not prevent the block from being garbage-collected)."
>
> Another important page is:
> http://download.plt-scheme.org/doc/insidemz/insidemz-Z-H-1.html,
> specifically:
>
> "IMPORTANT: Scheme values are garbage collected using a conservative
garbage
> collector, so pointers to MzScheme objects can be kept in registers, stack
> variables, or structures allocated with scheme_malloc. However, static
> variables that contain pointers to collectable memory must be registered
> using scheme_register_extension_global (see section 3)."
>
> There's more useful info on both those pages, but I think the above two
> quotes answer your questions.  The two examples you gave:
>
> > Scheme_Object * s1 = scheme_make_string();
> > Scheme_Object * s2 = scheme_make_string();
> > ...
> > return s1;
> ...
> > Scheme_Object **array = (Scheme_Object**) scheme_malloc (123);
> > Scheme_Object * s2 = scheme_make_string();
> > ...
> > return array;
>
> should both be safe, because the pointers are stored in stack variables
> which are accessible to the collector.  A problem would only arise when
> storing Scheme_Object pointers in memory returned by the regular malloc
> function.
>
> Anton
>



Posted on the users mailing list.