[PD-dev] atom types: extend or abuse?

Mathieu Bouchard matju at sympatico.ca
Wed Nov 12 03:04:42 CET 2003


On Tue, 11 Nov 2003, Miller Puckette wrote:

> > 2. Introducing one new atom type, generic and extendable.
> either of these first two would require adding code to dozens of 'switch'
> statements both inside and outside Pd.  Some code would run
> slower because of the extra cases to check.

jMax does it though. I was quite surprised to see Pd doesn't do it, and I
had to perform the following workaround.

> > 3. Using numbers as pointers or indices.
> > 3a. Plain memory addresses (gridflow?).  Validation is possible by
> > placing a header with a magic word at an address.  However,
> > representation of an address does not fit into one Pd atom, is
> > clumsy (particularly when maintaining 32/64-bit compatibility),

I store a 32-bit pointer as two 32-bit floats, which each can store 24-bit
unsigned integers exactly (it's guaranteed by IEEE standard).

> > and involves an overhead, possibly significant in some
> > applications.

It takes a dozen clock cycles or less, which is ~5 ns by today's
standards.

> I think 3a isn't really safe.

This is definitely not a major cause of crashing with GridFlow. I never
mangled those pointers accidentally, and I don't know anyone who'd dare
doing it on purpose, as it doesn't buy anyone anything.

>  I don't understand why 3b requires anything extra (you can just
> interpret numbers as indices and let it just be wrong if someone gives
> you a wrong number.)

In my case, I pass pointers I got from malloc, and I can't do range checks
on that. If anything, I can use a hashtable of integer keys, for example,
or some other sensible data structure, though a hashtable is the most
convenient by far.

> Each separate extension could make its own hash list and maintain its
> own name space.  You can generate symbols "x%d" to name things that
> the user didn't name.

BTW, how does one keep reference counts on anonymous data ?

> 6.  somehow overload Pd's "pointer" structure to point to
> user-definable data structures.

Could you give more info on this?

> and the pointer type already has a hook to protect against stale
> pointers.

What do you mean by that? weakrefs? refcounts?

________________________________________________________________
Mathieu Bouchard                       http://artengine.ca/matju





More information about the Pd-dev mailing list