win:possible c++ STL or mem issue

Jun 22, 2009 at 4:42pm

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));
}
#44492
Jun 23, 2009 at 4:03am

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

#160009
Jun 24, 2009 at 5:40am

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?

#160010
Jun 24, 2009 at 2:11pm

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

#160011
Jun 24, 2009 at 4:33pm

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.

#160012
Jun 30, 2009 at 7:39pm

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

best,
Tim

#160013

You must be logged in to reply to this topic.