win:possible c++ STL or mem issue
Hello,
My external needs to parse a stream of bytes into c++ objects that are then put into an STL list. After about 100 or so objects, max crashes.
My initial thought the max external was running out of memory so I ran the code under a simple windows console and there is no problem.
If this is the problem, is there a way to increase the memory size?
Here are snippets of the code:
#include
using namespace std;
class Element {
list *elements;
public:
Element(unsigned char *configStream);
};
Element::Element(unsigned char *configStream) {
elements = new list;
if (...)
elements->push_back(*new Element(configStreamNext+1));
}
I should add that I'm using MaxMSP 4.6. Building with Visual Studio 6.0.
Solved my problem by dumping the STL and not using C++ objects. Converted them to structs and use sysmem_newptr for memory allocation.
Max does not seem very C++ friendly.
Is there a guide to programming in C++ for Max?
I had an issue where my Max object struct contained a C++ object, e.g., something like:
typedef struct
{
t_object e_ob;
MyCPPObject e_test;
void *e_outlet;
} t_example;
.. the C++ object's constructor was not being called. This was on the Mac using Xcode admittedly and the solution was to ensure the file had the .cpp extension rather than .c. However, could it be somehthing like this? i.e., some part of the code is compiling as C rather C++?
Yep, that would cause a problem. My max external only contains a pointer to a C++ object, then I explicitly init it with 'new'.
I'm sure there are plenty other ways to mess up. Would be nice to see a working example in the docs.
There will be a C++/STL example in the next revision of the SDK.
best,
Tim