next up previous contents index
Next: Miscellaneous Features Up: Unstructured material or raw Previous: Related file (external) types   Contents   Index


Functions Summary

The following is a description of all the functions related to the Rawdata type. The list is in alphabetical order.

$ \bigcirc$Name


mw_alloc_rawdata - Allocate the data array of a Rawdata structure




$ \bigcirc$Summary


Rawdata mw_alloc_rawdata(rd,size)

Rawdata rd;

int size;




$ \bigcirc$Description


This function allocates the data array of a Rawdatastructure previously created using mw_new_rawdata. The size of the data is given by size, it corresponds to the number of bytes.

Values can be addressed after this call, if the allocation successed. There is no default values.

Do not use this function if rd has already an allocated array: use the function mw_change_rawdata instead.

The function mw_alloc_rawdata returns NULL if not enough memory is available to allocate the array. Your code should check this return value to send an error message in the NULL case, and do appropriate statement.




$ \bigcirc$Example

Rawdata rd=NULL; /* Internal use: no Input neither Output of module */
int i;

/* Create a rawdata of 1000 bytes */
if  ( ((rd = mw_new_rawdata()) == NULL) ||
      (mw_alloc_rawdata(rd,1000) == NULL) )
    mwerror(FATAL,1,"Not enough memory.\n");

/* Set the byte #i to the value i mod 256 */
for (i=0;i<rd->size;i++) rd->data[i] = i % 256;

$ \bigcirc$Name


mw_change_rawdata - Change the size of the data array of a Rawdata structure




$ \bigcirc$Summary


Rawdata mw_change_rawdata(rd, newsize)

Rawdata rd;

int newsize;




$ \bigcirc$Description


This function changes the memory allocation of the data array of a Rawdata structure, even if no previously memory allocation was done. The new size of the array is given by newsize, it corresponds to the number of allocated bytes.

The function mw_change_rawdata can also create the structure if the input rd = NULL. Therefore, this function can replace both mw_new_rawdata and mw_alloc_rawdata. It is the recommended function to allocate Rawdata variables used as input/output of modules. Since the function can set the address of rd, the variable must be set to the return value of the function (See example below).

The function mw_change_rawdata returns NULL if not enough memory is available to allocate the array. Your code should check this return value to send an error message in the NULL case, and do appropriate statement.




$ \bigcirc$Example

Rawdata Output; /* Output of module */

/* Set the size of the array to be 1000 bytes */
Output = mw_change_rawdata(Output, 1000);
if (Output == NULL) mwerror(FATAL,1,"Not enough memory.\n");

$ \bigcirc$Name


mw_copy_rawdata - Copy the data of a Rawdata+ structure into another one




$ \bigcirc$Summary


void mw_copy_rawdata(in, out)

Rawdata in,out;




$ \bigcirc$Description


This function copies the content of the array data of the Rawdata+ structure in into the array data of out. The variable out must be an allocated Rawdata structure of same size than in.

The speed of this function depends to the C library implementation, but it is usually very fast (trying to do faster is a waste of time).




$ \bigcirc$Example

Rawdata G; /* Needed Input */
Rawdata F; /* Optional Output */

  if (F) {
    printf("F option is active: copy G in F\n");
    if ((F = mw_change_rawdata(F, G->size)) == NULL)
        mwerror(FATAL,1,"Not enough memory.\n");
    else mw_copy_rawdata(G, F);
   }
  else  printf("F option is not active\n");

$ \bigcirc$Name


mw_delete_rawdata - Deallocate the data array of a Rawdata structure




$ \bigcirc$Summary


void mw_delete_rawdata(rd)

Rawdata rd;




$ \bigcirc$Description


This function deallocates the array values of a Rawdata structure previously allocated using
mw_alloc_rawdata or mw_change_rawdata, and the structure itself.

You should set rd = NULL after this call since the address pointed by rd is no longer valid.




$ \bigcirc$Example

Rawdata rd=NULL; /* Internal use: no Input neither Output of module */

if  ( ((rd = mw_new_rawdata()) == NULL) ||
      (mw_alloc_rawdata(rd,1000) == NULL) )
    mwerror(FATAL,1,"Not enough memory.\n");
/* .
   .
   (statement)
   .
   .
*/
mw_delete_rawdata(rd);
rd = NULL;

$ \bigcirc$Name


mw_new_rawdata - Create a new Rawdata structure




$ \bigcirc$Summary


Rawdata mw_new_rawdata();




$ \bigcirc$Description


This function creates a new Rawdata structure with an empty data array and size field set to 0. No data can be addressed at this time. The data should be allocated using the function mw_alloc_rawdata or mw_change_rawdata.

Do not use this function for input/output of modules, since the MegaWave2 Compiler already created the structure for you if you need it (See Volume one: ``MegaWave2 User's Guide''). Use instead the function mw_change_rawdata. Do not forget to deallocate the internal structures before the end of the module.

The function mw_new_rawdata returns NULL if not enough memory is available to create the structure. Your code should check this value to send an error message in the NULL case, and do appropriate statement.




$ \bigcirc$Example

Rawdata rd=NULL; /* Internal use: no Input neither Output of module */

if  ( ((rd = mw_new_rawdata()) == NULL) ||
      (mw_alloc_rawdata(rd,1000) == NULL) )
    mwerror(FATAL,1,"Not enough memory.\n");


next up previous contents index
Next: Miscellaneous Features Up: Unstructured material or raw Previous: Related file (external) types   Contents   Index
mw 2004-05-05