Re: Question about pointers and scalars

Christof Ressi <[email protected]>
Newsgroups gmane.comp.multimedia.puredata.general
Message-ID <[email protected]>
Hi,

yes, it's a design choice. A "gpointer" is basically a safe handle to a 
data structure object (scalar or array) and as such it has to know when 
it has been invalidated. There are several ways to implement this.

For example, every data structure object could maintain a list of all 
gpointers that currently reference it. When the object is deleted, it 
would have to notify all "gpointers". Conversely, when a gpointer is set 
to another object, it has to unregister from the old object and register 
to the new one. In C, gpointers and stubs are represented by the 
"t_gpointer" resp. "t_gstub" structs (see m_pd.h)

Miller chose a simpler solution: every canvas has a "stub" object with a 
reference count and a generation counter. When you set a gpointer, it 
not only saves a pointer to the data structure object, it also keeps a 
reference to the stub of the owning canvas. When a data structure object 
is deleted, the stub's generation counter is incremented and as a 
consequence all existing gpointers to *any* data structure object in 
that canvas are invalidated.

Unfortunately, since "t_gpointer" and "t_scalar" are public structs, I 
don't think there is a way to change the implementation without breaking 
backwards compatibility. I'm not even sure it would be worth the 
additional complexity.

---

Actually, I have had the same problem as you. The solution I've found is 
to never actually delete the scalars, instead I made the scalar 
invisible and set a special field inside scalar. When I wanted to create 
a scalar, I first traversed the canvas to see if there is already a 
"dead" scalar I could reuse. Of course, this only works as long as the 
user never *directly* deletes the scalars (e.g. with select + delete). 
Otherwise, the only solution is to re-traverse the canvas and update all 
your [pointer] objects...

Christof

On 19.10.2024 22:45, Jean-Yves Gratius wrote:
> Hi,
>
> I wonder why, in data structures, deleting a scalar invalidates all
> pointers to any other scalar in the same canvas.
>
> Is this a design choice ?
>
> I'm asking this because I planned to use pointers inside abstractions to
> handle scalars in a patch, for example for making them move.
>
> But may be I'm wrong, because if every time a scalar is deleted all
> [pointer]s have to [traverse( the patch to retrieve the scalar they
> pointed to, it seems not so optimized.
>
> Thanks in advance
>
> Regards
>
> JYG
>
>
> ---
> [email protected] - the Pure Data mailinglist
> https://lists.iem.at/hyperkitty/list/[email protected]/message/KVZQ3VBBJNV5LHEBZNMKLTUS7AF2HJX7/ 
>
>
> To unsubscribe send an email to [email protected] mailing list
> UNSUBSCRIBE and account-management -> https://lists.iem.at/
>

---
[email protected] - the Pure Data mailinglist
https://lists.iem.at/hyperkitty/list/[email protected]/message/TSYAJLGLBO4NT6OL3J6TLU4EJLQQTEPW/

To unsubscribe send an email to [email protected] mailing list
UNSUBSCRIBE and account-management -> https://lists.iem.at/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.