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

Mathieu Bouchard matju at artengine.ca
Sat Mar 21 15:57:02 CET 2009


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


More information about the Pd-dev mailing list