bpmnr/gsl_block.c

Go to the documentation of this file.
00001 
00005 #include <bpm/bpm_messages.h>
00006 #include <bpm/bpm_nr.h>
00007 
00008 gsl_block *gsl_block_alloc(const size_t n)
00009 {
00029   gsl_block * b;
00030 
00031   if (n == 0)
00032     {
00033       bpm_error("block length n must be positive integer in gsl_block_alloc(...)",
00034                 __FILE__, __LINE__);
00035       return NULL;
00036     }
00037 
00038   b = (gsl_block *) malloc (sizeof (gsl_block));
00039 
00040   if (b == 0)
00041     {
00042       bpm_error("failed to allocate space for block struct in gsl_block_alloc(...)",
00043                 __FILE__, __LINE__);
00044       return NULL;
00045     }
00046 
00047   b->data = (double *) malloc (n * sizeof (double));
00048 
00049   if (b->data == 0)
00050     {
00051       free (b);         /* exception in constructor, avoid memory leak */
00052       
00053       bpm_error("failed to allocate space for block data in gsl_block_alloc(...)",
00054                 __FILE__, __LINE__);
00055       return NULL;
00056     }
00057 
00058   b->size = n;
00059 
00060   return b;
00061 }
00062 
00063 void gsl_block_free (gsl_block * b)
00064 {
00065 
00066   free (b->data);
00067   free (b);
00068 }

Generated on Thu Jan 10 10:18:04 2008 for libbpm by  doxygen 1.5.1