View Single Post
Old 09-23-2011, 03:21 AM   #46
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 18,139
Default Defininig arrays

I used to run into problems defining arrays in JS FX, losing track of how the memory was being used and inadvertently reusing or overwriting memory slots.

I've come up with a fairly fool-proof syntax for defining arrays:
-- define the start address, number of items and end address together
-- for the next array, its start address = the end address of the previous array
-- each array item can consist of multiple elements
-- include any initialisation or constants (indented, for clarity)

Here is an example:

Code:
// -----------------------------------------------------------
    in_buffs = 1024;					// start of array
    noofbuffs = 256;					// number of items in array
    end_in_buffs = in_buffs + noofbuffs;		// end of array

        in_buffs[0] =  21; in_buffs[1] =  25; etc 	// initialisation of array

// -----------------------------------------------------------
    label_X = end_in_buffs;				// start of next array, = end of previous array	
    nooflabs = 32;						// number of items in array
    label_Y = label_X + nooflabs;
    label_Z = label_Y + nooflabs;
    end_labels = label_Z + nooflabs;			// end of array

        label_X[0] = 20; label_X[1] = 50; etc	// initialisation of array
        label_Y[0] = 110; label_Y[1] = 57; etc
        label_Z[0] = 40; label_Z[1] = 60; etc
 
// -----------------------------------------------------------
    chan_state = end_labels;				// start of next array, = end of previous array
        OFF = 0;						// constants for buff_state
        ON = 1;
   noofchans = 16;
   end_chan_states = chan_state + noofchans;	// end of array
 
        memset(chan_state, OFF, noofchans);	// initialisation of array (dest, value, length)
        chan_state[2] = ON;

// -----------------------------------------------------------
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
DarkStar is offline   Reply With Quote