next up previous contents index
Next: The structure Flists Up: Lists of n-tuple reals Previous: Related file (external) types   Contents   Index


Functions Summary

The following is a description of all the functions related to the Flist type. The list is in alphabetical order. Notice that these functions do not manage the data field.

$ \bigcirc$Name


mw_change_flist - Define and allocate a Flist structure




$ \bigcirc$Summary


Flist mw_change_flist(l,max_size,size,dim)

Flist l; int max_size,size,dim;




$ \bigcirc$Description


This function changes the memory allocation of the values array of a Flist structure, even if no previously memory allocation was done. The new size (number of elements) of the structure is given by size, the size to allocate (maximal number of elements) by max_size, and the dimension by dim.

It can also create the structure if the input l = NULL. Therefore, this function can replace both mw_new_flist and mw_realloc_flist. Since the function can set the address of l, the variable must be set to the return value of the function (See example below).

The function mw_change_flist returns NULL if not enough memory is available to allocate the structure or the values array, and an error message is issued. Your code should check this return value to eventually send a fatal error message in the NULL case, and do appropriate statement.




$ \bigcirc$Example

Flist l;

/* 
   Allocate l to handle at most 10 samples of couples (2) of 
   floating point values, the default number of samples being 0. 
*/
l = mw_change_flist(NULL,10,0,2);
if (!l) mwerror(FATAL,1,"Not enough memory to continue !\n");

$ \bigcirc$Name


mw_clear_flist - Clear the array of a Flist structure




$ \bigcirc$Summary


void mw_clear_flist(l,v)

Flist l; float v;




$ \bigcirc$Description


This function clears the values array by filling it with the value v (up to the current number of samples).




$ \bigcirc$Example

Flist l;

/* 
   Allocate l to handle at most 10 samples of couples (2) of 
   floating point values, the default number of samples being 5. 
*/
l = mw_change_flist(NULL,10,5,2);
if (!l) mwerror(FATAL,1,"Not enough memory to continue !\n");

/* 
  Clear the 5 current samples with 0.
*/
mw_clear_flist(l,0.0);

$ \bigcirc$Name


mw_copy_flist - Copy a the array Flist structure




$ \bigcirc$Summary


Flist mw_copy_flist(in,out)

Flist in,out;




$ \bigcirc$Description


This function copies the values array and data field of the Flist structure in into out. The duplicated Flist out is allocated to at least the current size of in.

Since the function can set the address of out, the variable must be set to the return value of the function (See example below).

The function mw_copy_flist returns NULL if not enough memory is available to allocate the structure or the values array, and an error message is issued. Your code should check this return value to eventually send a fatal error message in the NULL case, and do appropriate statement.




$ \bigcirc$Example

Flist in,out=NULL;

/* 
   Allocate in to handle at most 10 samples of couples (2) of 
   floating point values, the current number of samples being 5. 
*/
in = mw_change_flist(NULL,10,5,2);
if (!in) mwerror(FATAL,1,"Not enough memory to continue !\n");

/* 
  Clear the 5 current samples with 1.
*/
mw_clear_flist(in,1.0);

/*
 Copy in into out. Allocated size for out is 5 samples.
*/
out=mw_copy_flist(in,out);
if (!out) mwerror(FATAL,1,"Not enough memory to copy flist !\n");

$ \bigcirc$Name


mw_delete_flist - Delete the array and the Flist structure




$ \bigcirc$Summary


void mw_delete_flist(l)

Flist l;




$ \bigcirc$Description


This function deletes the values array and the structure itself. Warning : the memory of the user-defined field data is not freed. If this field has been allocated, you should free it before calling mw_delete_flist.




$ \bigcirc$Example

Flist l;

/* 
   Allocate l to handle at most 10 samples of couples (2) of 
   floating point values, the default number of samples being 5. 
*/
l = mw_change_flist(NULL,10,5,2);
if (!l) mwerror(FATAL,1,"Not enough memory to continue !\n");

/* 
  Allocate the data field for 20 integers.
*/
l->data_size=20*sizeof(int);
l->data= (int *)malloc(l->data_size);
if (!l->data) mwerror(FATAL,1,"Not enough memory to continue !\n");


/*
    ... (statement)...
*/

/* 
  Free the list, including data field. 
*/
free(l->data);
mw_delete_flist(l);

$ \bigcirc$Name


mw_enlarge_flist - Enlarge the array of a Flist




$ \bigcirc$Summary


Flist mw_enlarge_flist(l)

Flist l;




$ \bigcirc$Description


This function performs a memory reallocation on the array l->values to increase the number of elements that can be recorded. The enlargement factor is fixed by the constant MW_LIST_ENLARGE_FACTOR defined in the include file list.h. This function is useful when one does not know by advance the size of the list, and when one wish to avoid multiple reallocations.

If not enough memory is available to perform the reallocation, an error message is issued and the function returns NULL. Otherwise, the function returns l.




$ \bigcirc$Example

/* Fill a flist with diagonal points using mw_enlarge_flist 
   up to a random size, unknown by advance.
*/

Flist l; 

l = mw_change_flist(NULL,2,0,2);
if (l==NULL) mwerror(FATAL,1,"Not enough memory to continue !\n");
i=0;
do
  {
   if ((2*i == l->max_size) && (!mw_enlarge_flist(l)))
       mwerror(FATAL,1,"Not enough memory to continue !\n");
   l->values[i++] = l->values[i++] = i;
  }  while (rand() != 0);
l->size=(i+1)/2;

$ \bigcirc$Name


mw_new_flist - Create a Flist structure




$ \bigcirc$Summary


Flist mw_new_flist()




$ \bigcirc$Description


This function creates a new Flist structure. The fields are initialized to 0 or NULLvalue. The function returns the address of the new structure, or NULL if not enough memory is available.




$ \bigcirc$Example

Flist l;

/*
  Define the structure
*/
l = mw_new_flist();
if (!l) mwerror(FATAL,1,"Not enough memory to define the list !\n");

/* 
  At that time, the FList is empty.
*/

$ \bigcirc$Name


mw_realloc_flist - Realloc the array of a Flist




$ \bigcirc$Summary


Flist mw_realloc_flist(l,n)

Flist l;

int n;




$ \bigcirc$Description


This function performs a memory reallocation on the array l->values so that at most n elements can be recorded.

If not enough memory is available to perform the reallocation, an error message is issued and the function returns NULL. Otherwise, the function returns l.




$ \bigcirc$Example

Flist l;

/* 
   Allocate l to handle at most 1000 samples of 500-tuple of 
   floating point values, the default number of samples being 1000. 
*/
l = mw_change_flist(NULL,1000,1000,500);
if (!l) mwerror(FATAL,1,"Not enough memory to continue !\n");

/*
    ... (statement)...
*/

/*
   Now we need space for 20 samples only : by doing reallocation,
   we allow to free some memory.
*/
l = mw_realloc_flist(l,20);
if (!l) mwerror(FATAL,1,"Couldn't realloc flist !\n");


next up previous contents index
Next: The structure Flists Up: Lists of n-tuple reals Previous: Related file (external) types   Contents   Index
mw 2004-05-05