[plt-scheme] Memory management and MzScheme
Hi there,
I am trying to build an extension for MzScheme on WindowsXp/Visual Studio
7.0. I seem to be unable to figure out what is wrong with:
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?
Thanks in advance,
-pp