Re: [PD-dev] How to construct a dynamic length list in PD external?

2009-03-22 Thread Mike McGonagle
Why not just create a binbuf object, append all the atoms to it, and
then extract the length and atoms vector...

t_atom a;
t_binbuf b = binbuf_new();
while(more_data) {
   SETSYMBOL(&a, camera_data);
   binbuf_add(b, 1, &a);
}
outlet_anything(x -> x_obj.ob_outlet, &s_list, binbuf_getnatom(b),
binbuf_getvec(b));
binbuf_free(b);

Mike

On Fri, Mar 20, 2009 at 6:07 PM, B. Bogart  wrote:
> Hey all,
>
> I searched the archives and looked at some of the code in SVN, but I'm
> still unsure how to do this.
>
> I have a nested for loop that grabs the config options from the PTP
> camera. The length depends on the camera and its mode.
>
> How can I append each name to a list suitable to be used by outlet_list?
>
> Anyone keeping a collection of PD C external snippets?
>
> Thanks,
> B.
>
> ___
> Pd-dev mailing list
> Pd-dev@iem.at
> http://lists.puredata.info/listinfo/pd-dev
>



-- 

Fred Allen  - "The first time I sang in the church choir; two hundred
people changed their religion."

___
Pd-dev mailing list
Pd-dev@iem.at
http://lists.puredata.info/listinfo/pd-dev


Re: [PD-dev] How to construct a dynamic length list in PD external?

2009-03-21 Thread Mathieu Bouchard

On Sat, 21 Mar 2009, Claude Heiland-Allen wrote:

B. Bogart wrote:

I have a nested for loop that grabs the config options from the PTP
camera. The length depends on the camera and its mode.

choice 1 (if maximum length is known):
choice 2 (if maximum length is not known):
choice 3 (an alternative):


choice 4: malloc() just what you need, and then realloc() for any 
subsequent growth.


choice 5: malloc() some size, keep track of the size allocated, keep track 
of the size used, realloc() only when needed, by increasing the size 
allocated by some percentage.


The latter is how many resizable arrays work in various languages. It 
seems like choice #4 works fast, as it is used by much of Pd without 
taking much time, but there's no real guarantee that calling realloc() 
that often should be that fast (and I think that Pd's internals are just 
being lucky with it). Anyhow, for just a set of camera options, it doesn't 
matter at all, it could be pretty much any speed.


 _ _ __ ___ _  _ _ ...
| Mathieu Bouchard - tél:+1.514.383.3801, Montréal, Québec___
Pd-dev mailing list
Pd-dev@iem.at
http://lists.puredata.info/listinfo/pd-dev


Re: [PD-dev] How to construct a dynamic length list in PD external?

2009-03-20 Thread Claude Heiland-Allen

B. Bogart wrote:

Hey all,

I searched the archives and looked at some of the code in SVN, but I'm
still unsure how to do this.

I have a nested for loop that grabs the config options from the PTP
camera. The length depends on the camera and its mode.

How can I append each name to a list suitable to be used by outlet_list?


choice 1 (if maximum length is known):

allocate t_atom out[MAX_LENGTH] on the stack (as a normal variable). 
set argc to the actual length.


choice 2 (if maximum length is not known):

loop through once to get the length
malloc() sufficient space
loop through again to copy the data
send to outlet
free() the space

choice 3 (an alternative):

send each config option to the outlet separately (may be more useful 
than having to parse a list later?)



Claude
--
http://claudiusmaximus.goto10.org

___
Pd-dev mailing list
Pd-dev@iem.at
http://lists.puredata.info/listinfo/pd-dev


[PD-dev] How to construct a dynamic length list in PD external?

2009-03-20 Thread B. Bogart
Hey all,

I searched the archives and looked at some of the code in SVN, but I'm
still unsure how to do this.

I have a nested for loop that grabs the config options from the PTP
camera. The length depends on the camera and its mode.

How can I append each name to a list suitable to be used by outlet_list?

Anyone keeping a collection of PD C external snippets?

Thanks,
B.

___
Pd-dev mailing list
Pd-dev@iem.at
http://lists.puredata.info/listinfo/pd-dev