Calko
July 30th, 2003, 11:19 PM
My main function is written in C++ .NET and it calls a static function written in unmanged C++ declared and implemented in a header file.
// managed.cpp
#include "Unmanged.h"
__gc class MyManaged{
main(){
// if I take out the following line, I get a runtime error when I
// call malloc() in Unmanaged.h
// but if the following line is in place in the managed.cpp file,
// then I don't get the runtime error in Unmanaged.h
// but it seems that some how the memory allocated
// Unmanaged.h is corrupt
char * c = (char*) malloc(200);
StaticUnmanagedCall();
}
};
// Unmanaged.h
class MyUnmanaged{
static void StaticUnmanagedCall(){
// Runtime will throw an exception - can not allocate memory
// if malloc was not called in MyManaged::Main()
// But if malloc was called in MyManaged::Main() it seems that
// the memory gets corrupted during this call.
char *c = (char*) malloc(200);
}
};
I think the managed malloc() call just "fooled" the runtime? My best guess:confused: And the memory malloc-ed in unmanaged static function is actually hijaked memory? I'm totally confused :confused: Is it not possible to malloc() memory in a static function?
// managed.cpp
#include "Unmanged.h"
__gc class MyManaged{
main(){
// if I take out the following line, I get a runtime error when I
// call malloc() in Unmanaged.h
// but if the following line is in place in the managed.cpp file,
// then I don't get the runtime error in Unmanaged.h
// but it seems that some how the memory allocated
// Unmanaged.h is corrupt
char * c = (char*) malloc(200);
StaticUnmanagedCall();
}
};
// Unmanaged.h
class MyUnmanaged{
static void StaticUnmanagedCall(){
// Runtime will throw an exception - can not allocate memory
// if malloc was not called in MyManaged::Main()
// But if malloc was called in MyManaged::Main() it seems that
// the memory gets corrupted during this call.
char *c = (char*) malloc(200);
}
};
I think the managed malloc() call just "fooled" the runtime? My best guess:confused: And the memory malloc-ed in unmanaged static function is actually hijaked memory? I'm totally confused :confused: Is it not possible to malloc() memory in a static function?