[PD] Handling numbers read from a file
Matteo Sisti Sette
matteosistisette at gmail.com
Tue Mar 2 16:03:24 CET 2010
> 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
More information about the Pd-list
mailing list