[PD-dev] how to dinamically allocate t_atom & t_float size?

Christof Ressi info at christofressi.com
Fri Dec 4 15:11:05 CET 2020


Off topic.

Since C++11, using raw "new" is a code smell, because it easily causes 
problems as the one below. Instead use smart pointers, which will 
automatically free the memory once they go out of scope:

auto at = std::unique_ptr<t_atom[]>(new t_atom[c]);

Or even better, but requires C++14:

auto at = std::make_unique<t_atom[]>(ac);

In both cases, note the square brackets!

Christof

On 04.12.2020 12:40, Claude Heiland-Allen wrote:
> Hi,
>
> On 03/12/2020 23:58, David Rush wrote:
>
>> if you want to do it the C++ way without a std::vector<t_atom>
>>
>>         t_atom* at = new t_atom[ac];
>>
>> but again you will have to
>>
>>         delete at;
>>
> This should be delete[] at;
>
>
> Claude





More information about the Pd-dev mailing list