[flext] Pass pointer from one external to another

Patrick Gampp Patrick.Gampp at posteo.de
Fri Apr 17 15:26:25 UTC 2015


Thanks for the hint Thomas, it brought me directly to the solution. Here 
is how I did it:

/* ------------- eject parameter handle from external 1  ------------*/
/* handle to float converter */
union
{
     myParams* hPar;
     float f;
} h2f; /* only works if sizeof(myParams*) == sizeof(float) */

AtomList paramStructHandleList(1);

h2f.hPar = &ParamsExt1;
SetFloat(paramStructHandleList[0], h2f.f);
ToOutList(numOutletsInfrontOfListOutlet + 1, paramStructHandleList);



/* ---------- receive parameter handle at external 2  ----------*/
/* float to handle converter */
union
{
     myParams* hPar;
     float f;
} f2h; /* only works if sizeof(myParams*) == sizeof(float) */

f2h.f = GetAFloat(paramStructHandleList[0]);
myParams* handleToParamsExt1= f2h.hPar;






Am 17.04.2015 um 09:47 schrieb Thomas Grill:
> Hi Patrick,
> while passing around pointer can be a pretty dangerous thing to do, it is actually done, e.g. by my vasp external library.
> The pointer atom types in Pd and flext are intended to be used with Pd data structures, not for general C memory pointers.
> The easiest way is to cast the pointer to a 64-bit unsigned integer, and convert this again into a numerical representation supported by Pd. Since Pd doesn't support integers you have to split the possibly 64 bit wide pointer address into multiple integers with at most 23 binary digits (that's the mantissa size of a single precision float). You can, e.g., use a list of three integers with 22 bits each.
> I hope this helps, best,
> Thomas
> --
> Thomas Grill
> http://grrrr.org
>
>
>
> Am 16.04.2015 um 19:56 schrieb Patrick Gampp <Patrick.Gampp at posteo.de>:
>
>> Hi flext list,
>>
>> I want to pass a pointer from one pd flext external to another. The pointer points to a parameter struct, which is used by both externals.
>>
>> So far, I found SetPointer(t_atom &a,t_gpointer *p), which I thought can help me. But I cannot manage to put my pointer into the function.
>>
>> Here is an example what I want:
>>
>> myStructType myStruct;
>> Atomlist myList(10);
>> SetPointer(myList[0], &myStruct); // does not work since &myStruct is not of type *t_gpointer.
>>
>> How can I manage to put &myStruct into the atomlist? Or is there another way to pass pointers from one external to another?
>>
>> Cheers and thanks in advance,
>> Patrick
>> _______________________________________________
>> http://grrrr.org/ext/flext
>>
>> flext mailing list
>> flext at grrrr.org
>> http://grrrr.org/cgi-bin/mailman/listinfo/flext
>



More information about the flext mailing list