[PD-dev] External development: preventing several copies of external

Alexandre Clément alexandre.r.clement at gmail.com
Mon Jun 15 00:25:24 CEST 2015


Wow, never would have thought about that...
Tried it out right out, worked like a charm!

Thanks a lot, Martin!

Alex

On 14 June 2015 at 21:44, Martin Peach <chakekatzil at gmail.com> wrote:

> On Sun, Jun 14, 2015 at 3:36 PM, Alexandre Clément <
> alexandre.r.clement at gmail.com> wrote:
>
>> Hello all!
>>
>> I'm creating an external which should only allow one copy loaded at the
>> same time.
>> Is there a way to check this upon creation?
>>
>> I tried going the same approach as checking if a receiver exists before
>> attempting to send, but it doesn't seem to work.
>>
>> if (gensym("class_name")->s_thing) {
>>     post("Exists!");
>>     return false;
>> }
>>
>> Because gensym generates the symbol if it wasn't already in the list.
> What I do is have a global variable outside the class struct and check if
> it is not zero before instantiating a new object.
> Since c is guaranteed to initialize globals to zero, the first object
> created can set it to some other value. Maybe some more trickery will be
> needed if the object is deleted and recreated, possibly the code is still
> in memory and the global will have the non-zero value; in this case the
> free routine should zero the global,
>
> Martin
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puredata.info/pipermail/pd-dev/attachments/20150614/38a54d1a/attachment.html>


More information about the Pd-dev mailing list