creating a std:vector of t_atom

Monami's icon

I want to do a std:vector of t_atom from the one that are passed at the creation of my object...

I have those typedef:

typedef C74::t_symbol MaxSymbol_t;
typedef C74::t_atom MaxAtom_t;
typedef std::vector AttributeVec_t;
typedef AttributeVec_t::iterator Attribute_itt;
typedef AttributeVec_t::const_iterator Attribute_citt;

here is my function


Attribute_t(long ac, MaxAtom_t* av):attributes_()
{

   MaxAtom_t* elem = av;
   MaxAtom_t* end = av + ac*sizeof(*av);

   MaxAtom_t* tmpAtom = 0;
   long* nbAtom = 0;

   for(; elem !=end; ++elem)
   {
      tmpAtom = new MaxAtom_t();
      tmpAtom->a_type = elem->a_type;
      tmpAtom->a_w = elem->a_w;

      attributes_.push_back(tmpAtom);
   }
}

and then later I free the memory...

~Attribute_t() throw()
{
   Attribute_itt end = attributes_.end();
   Attribute_itt itt = attributes_.begin();

   for(; itt != end; ++itt)
   {
      delete *itt;
   }
}

But I get this when I delete them...
MaxMSP Runtime(493,0xa0471500) malloc: *** error for object 0x16630d20: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

Can someone enlight me?

thks alot

Mani

+1m's icon

The best way to figure this out is to do exactly what it says:

* in the Xcode project for your external, set up the Max Runtime as your "custom executable"

* In the breakpoints window, define a breakpoint that will stop on the function called "malloc_error_break".

* start up the debugger...

Then when the debugger pauses execution, you'll see what it is trying to free. Working backwards from there, hopefully you'll get it.

Monami's icon

Thanks i didn't know you could setup a break point like this... what is malloc_error_break is it like a symbol? Also on a diffrent note, do you know how to make xcode break at every exception?

Now on my little problem I figured it out... at first my point arithmetic was wrong:
I was doing:
MaxAtom_t* end = av + ac*sizeof(*av);

When I should be doing
MaxAtom_t* end = av + ac;

I was thinking in term of addresses. I realise that when I posted what I was actually copping and them I had to think because i was passing stuff by ref without copying it and in the end I was deleting stuff that I didn't allocated now it is working fine.

But, My algo to copy atom is kind of tedious now isn't there a way to copy an atom to and other like

t_atom atomcopy = atomorginal;

and I saw a function call postargs in the documentation but it doesn't seam to find it... In which include file this is?

thanks alot!!

Mani