xmos / lib_src

Sample rate conversion library
Other
16 stars 18 forks source link

Should the API allocate the 4 integers in the structure? #18

Open henkmuller opened 7 years ago

henkmuller commented 7 years ago

(this is related to lib_dsp - it may have been fixed in lib_src)

The current data structure contains pointers to a 3-word and 1-word array::

typedef struct dsp_ds3_ctrl_t { int in_data; // Pointer to input data (3 samples) int out_data; // Pointer to output data (1 sample) ...

rather than the two arrays itself::

typedef struct dsp_ds3_ctrl_t { int in_data[3]; // Pointer to input data (3 samples) int out_data[1]; // Pointer to output data (1 sample) ...

The latter saves code space (no need to initialise the pointers), it saves memory space (4 words rather than 6), and best of all, you cannot forget to initialise them.

The former case optimises for a case where you move something along a buffer; something that only works if the buffer is on the same core as yourself, and not wrapped around.

Is there any good reason not to pre-allocate the arrays?

ed-xmos commented 7 years ago

This was the digimath implementation which got carried across. I thin it borrows it’s structure from the other src modules where the number of input/outputs vary. In the case of ds3, there is no reason to not pre-allocate the arrays, other than forcing an API change. Ed

On 1 Mar 2017, at 14:45, Henk Muller notifications@github.com<mailto:notifications@github.com> wrote:

(this is related to lib_dsp - it may have been fixed in lib_src)

The current data structure contains pointers to a 3-word and 1-word array::

typedef struct dsp_ds3_ctrl_t { int in_data; // Pointer to input data (3 samples) int out_data; // Pointer to output data (1 sample) ...

rather than the two arrays itself::

typedef struct dsp_ds3_ctrl_t { int in_data[3]; // Pointer to input data (3 samples) int out_data[1]; // Pointer to output data (1 sample) ...

The latter saves code space (no need to initialise the pointers), it saves memory space (4 words rather than 6), and best of all, you cannot forget to initialise them.

The former case optimises for a case where you move something along a buffer; something that only works if the buffer is on the same core as yourself, and not wrapped around.

Is there any good reason not to pre-allocate the arrays?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/xmos/lib_src/issues/18, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AAmLbTTk1QLIUy_rPJeat89j2nn8vX2hks5rhYRvgaJpZM4MPvgD.