Forums > Dev

win:possible c++ STL or mem issue

Jun 22 2009 | 4:42 pm


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:

using namespace std;

class Element {
	list *elements;
	Element(unsigned char *configStream);

Element::Element(unsigned char *configStream) {

	elements = new list;

	if (...)
		elements->push_back(*new Element(configStreamNext+1));
Jun 23 2009 | 4:03 am

I should add that I’m using MaxMSP 4.6. Building with Visual Studio 6.0.

Jun 24 2009 | 5:40 am

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?

Jun 24 2009 | 2:11 pm

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++?

Jun 24 2009 | 4:33 pm

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.

Jun 30 2009 | 7:39 pm

There will be a C++/STL example in the next revision of the SDK.


Viewing 6 posts - 1 through 6 (of 6 total)

Forums > Dev