next up previous contents
Next: 4. Programming in-place functions Up: 3. Programming PIO functions Previous: 3.6.3 Evalend callbacks   Contents

3.7 Memory allocation revisited

When you are using PIO, memory allocation becomes rather more complicated than it was before. There are essentially two types of memory which your function might want to use for working space: memory which is associated with each instance of your function (remember that two copies of you function may be joined together in a pipeline and be running at the same time -- you can't just use global variables), and memory which is local to each sequence which VIPS starts on your function.

The first type, memory local to this function instance, typically holds copies of any parameters passed to your image processing function, and links to any read-only tables used by sequences which you run over the image. The structure ClipState in the example below is of this sort.

The second type of memory, memory local to a sequence, should be allocated in a start function. Because this space is private to a sequence, it may be written to, as in the example below. Start and stop functions are guaranteed to be single-threaded, so you may write to the global state within them.


next up previous contents
Next: 4. Programming in-place functions Up: 3. Programming PIO functions Previous: 3.6.3 Evalend callbacks   Contents
John Cupitt 2004-11-02