@@ 18,10 18,42 @@ class Class;
using Inlet = std::unique_ptr<t_inlet, void(*)(t_inlet*)>;
using Outlet = std::unique_ptr<t_outlet, void(*)(t_outlet*)>;
+struct PdBytes {
+ void *ptr;
+ size_t sz;
+ void *get() { return ptr; }
+ PdBytes(size_t size):sz(size) {
+ ptr = (void*)getzbytes(size);
+ assert(ptr);
+ }
+
+ PdBytes():sz(0),ptr(nullptr) {
+ }
+
+ PdBytes(PdBytes&& b) {
+ std::swap(ptr, b.ptr);
+ std::swap(sz, b.sz);
+ }
+
+ PdBytes(const PdBytes&) = delete;
+
+ PdBytes& operator=(PdBytes&& from) {
+ std::swap(ptr, from.ptr);
+ std::swap(sz, from.sz);
+ return *this;
+ }
+
+ void operator=(const PdBytes&) = delete;
+
+ ~PdBytes() {
+ if (ptr) freebytes(ptr, sz);
+ }
+};
+
struct Instance {
std::vector<Inlet> inlets;
std::vector<Outlet> outlets;
- std::unique_ptr<char[]> kstate;
+ PdBytes kstate;
std::vector<float> outBuffer;
};
@@ 213,12 245,11 @@ public:
outScratch.reset(new char[k->result_type_size]);
}
- std::unique_ptr<char[]> ConstructInstance() {
- auto space = std::unique_ptr<char[]>(new char[k->get_size()]);
- memset(space.get(), 0, k->get_size());
+ PdBytes ConstructInstance() {
+ PdBytes space(k->get_size());
KReflect::Configure(*k, *this);
k->construct(space.get(), nullptr);
- return std::move(space);
+ return space;
}
void AddConnections(t_wrapper* wrap) {