[PD] Handling numbers read from a file

Hans Roels hans.roels at base.be
Wed Mar 3 09:17:24 CET 2010


There's a simple solution to know the size of an array in Pd vanilla 
(it has been posted on this list before). If your array is called 
example, send a bang to
[expr size("example")]

Hansr

At 16:03 2/03/2010, Matteo Sisti Sette wrote:
> > As all my data are numbers, [tabread] should work fine. Although in
> > this
> > case, I do not know how to know the number of values in advance to
> > resize the table prior to loading the data.
>
>If you store the numbers one per line in the text file, then you 
>have two options:
>
>A) Load the file, then bang [textfile] in an [until] loop (until the 
>end is reached) and resize the table at each bang by incrementing 
>its size by one as you add one more number. Quite inefficient since 
>I guess it may have to reallocate memory at each resize
>
>B) Load the file, then do one first "scan" of [textfile] (banging it 
>in an [until] loop) just to count the numbers, then resize the table 
>to the number of counted elements, then start all over again to 
>store the numbers into the table
>
>If, on the other hand, you store all the number in one list in the 
>text file, then you can load it, bang [textfile] only once, and use 
>a [list length] to know the number of elements and resize the table 
>accordingly, and then prepend a 0 to the list and send the whole 
>list to the table to store the elements.
>
>I think the latter solution should be a little (or significantly?) 
>more efficient.
>
>--
>Matteo Sisti Sette
>matteosistisette at gmail.com
>http://www.matteosistisette.com
>
>_______________________________________________
>Pd-list at iem.at mailing list
>UNSUBSCRIBE and account-management -> 
>http://lists.puredata.info/listinfo/pd-list





More information about the Pd-list mailing list