[plt-scheme] Memory management and MzScheme

From: Pedro Pinto (ppinto at cs.cmu.edu)
Date: Sat Nov 23 18:05:54 EST 2002

Thank your for the reply. I did poke around MzScheme's sources and as far as
I could tell scheme_build_list will take its input and create a list by
copying the input into pairs. I did not see anything in the code that
implied the need for specially allocated memory.

-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 5:22 PM
Subject: RE: [plt-scheme] Memory management and MzScheme


> > static Scheme_Object *scheme_test(int argc, Scheme_Object **argv)
> > {
> >     std::vector<Scheme_Object *> v;
> >     for(int i =0 ; i < 10000; i++)
> >         v.push_back(scheme_make_string ("test"));
> >     return scheme_build_list (10000,&v[0]);
> > }
> >
> > This build a list of strings. MzScheme displays the first elements
> > of the list correctly but at some point the list is corrupted. I've
> > replaced the offending code with:
> >
> > static Scheme_Object *scheme_test2(int argc, Scheme_Object **argv)
> > {
> >     Scheme_Object** result = (Scheme_Object**) scheme_malloc
> > (sizeof(Scheme_Object*) * 10000);
> >     for(int i =0 ; i < 10000; i++)
> >         result[i] = scheme_make_string ("test2");
> >     return scheme_build_list (10000,result);
> > }
> >
> > which works fine. Using a stack alocated array also works while
> > using new or malloc fails. What am I missing?
>
> The obvious possibly problematic difference between your two examples is
> that one is using scheme_malloc and the other is not.  I haven't actually
> done any extension work with MzScheme specifically, but I'd guess that
this
> could lead to trouble.
>
> (If I'm wrong, I trust that a PLT person will correct me...)
>
> If that is the problem, it could presumably be corrected by implementing a
> custom STL allocator which uses scheme_malloc (assuming something like
this
> isn't already provided by PLT).
>
> Anton
>



Posted on the users mailing list.