]> Creatis software - gdcm.git/commitdiff
ENH: change malloc/calloc/free with there c++ equivalent
authormalaterre <malaterre>
Fri, 23 Apr 2004 02:51:13 +0000 (02:51 +0000)
committermalaterre <malaterre>
Fri, 23 Apr 2004 02:51:13 +0000 (02:51 +0000)
src/gdcmDicomDir.cxx
src/gdcmFile.cxx
src/gdcmHeader.cxx
src/gdcmParsePixels.cxx
src/gdcmParser.cxx
src/gdcmRLE.cxx

index 172a1a6faafa4adf1ac2f7a42935fb93716b6628..5b1b6e4904841fd0e34e5634e8649239c93cd62a 100644 (file)
@@ -74,10 +74,10 @@ gdcmDicomDir::gdcmDicomDir(const char *FileName, bool parseDir,
 
       if(strlen(FileName)==1 && FileName[0]=='.') { // user passed '.' as Name
                                             // we get current directory name
-         char*dummy=(char*) malloc(1000);
-         getcwd(dummy,(size_t)1000);
+         char* dummy= new char[1000];
+         getcwd(dummy, (size_t)1000);
          SetFileName(dummy); // will be converted into a string
-         free(dummy);        // no longer needed   
+         delete[] dummy;        // no longer needed   
       }
 
       if(parseDir)
@@ -307,11 +307,10 @@ bool gdcmDicomDir::Write(std::string fileName)
       return(false);
    }
 
-   char * filePreamble;
-   filePreamble=(char*)calloc(128,1);
+   char * filePreamble = new char[128];
    fwrite(filePreamble,128,1,fp1);
    fwrite("DICM",4,1,fp1);
-   free(filePreamble);        
+   delete[] filePreamble;
    UpdateDirectoryRecordSequenceLength();
    WriteEntries(fp1);
 
index 769f3edb5d05b03a37dd6ab1ce3ee60648e248c6..8e12ec3ac10e3d866f04fb814c02aff5bb97b138 100644 (file)
@@ -224,7 +224,7 @@ size_t gdcmFile::GetImageDataSizeRaw(void) {
  *          NULL if alloc fails 
  */
 void * gdcmFile::GetImageData (void) {
-   PixelData = (void *) malloc(lgrTotale);
+   PixelData = new char[lgrTotale];
    if (PixelData)
       GetImageDataIntoVector(PixelData, lgrTotale);
       
@@ -261,7 +261,7 @@ size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t MaxSize) {
       return lgrTotale; 
                             
    // from Lut R + Lut G + Lut B
-   unsigned char * newDest = (unsigned char *)malloc(lgrTotale);
+   unsigned char * newDest = new (unsigned char)[lgrTotale];
    unsigned char * a       = (unsigned char *)destination;      
    unsigned char * lutRGBA =                  Header->GetLUTRGBA();
    if (lutRGBA) {          
@@ -274,7 +274,7 @@ size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t MaxSize) {
          *a++ = lutRGBA[j+1];
          *a++ = lutRGBA[j+2];
       }
-      free(newDest);
+      delete[] newDest;
     
    // now, it's an RGB image
    // Lets's write it in the Header
@@ -321,7 +321,7 @@ void * gdcmFile::GetImageDataRaw (void) {
       lgrTotale /= 3;  // TODO Let gdcmHeadar user a chance 
                        // to get the right value
                       // Create a member lgrTotaleRaw ???
-   PixelData = (void *) malloc(lgrTotale);
+   PixelData = new char[lgrTotale];
    if (PixelData)
       GetImageDataIntoVectorRaw(PixelData, lgrTotale);
    PixelRead=1; // PixelRaw
@@ -492,7 +492,7 @@ size_t gdcmFile::GetImageDataIntoVectorRaw (void* destination, size_t MaxSize) {
             int l = Header->GetXSize()*Header->GetYSize();
             int nbFrames = Header->GetZSize();
 
-            unsigned char * newDest = (unsigned char*) malloc(lgrTotale);
+            unsigned char * newDest = new (unsigned char)[lgrTotale];
             unsigned char *x  = newDest;
             unsigned char * a = (unsigned char *)destination;
             unsigned char * b = a + l;
@@ -524,7 +524,7 @@ size_t gdcmFile::GetImageDataIntoVectorRaw (void* destination, size_t MaxSize) {
                }
            }
             memmove(destination,newDest,lgrTotale);
-            free(newDest);
+            delete[] newDest;
 
         } else {
          
@@ -533,7 +533,7 @@ size_t gdcmFile::GetImageDataIntoVectorRaw (void* destination, size_t MaxSize) {
 
             int l = Header->GetXSize()*Header->GetYSize()*Header->GetZSize();
 
-            char * newDest = (char*) malloc(lgrTotale);
+            char * newDest = new char[lgrTotale];
             char * x = newDest;
             char * a = (char *)destination;
             char * b = a + l;
@@ -545,7 +545,7 @@ size_t gdcmFile::GetImageDataIntoVectorRaw (void* destination, size_t MaxSize) {
                *(x++) = *(c++);  
             }           
             memmove(destination,newDest,lgrTotale);
-            free(newDest);
+            delete[] newDest;
         }        
          break;
        }     
@@ -699,10 +699,10 @@ bool gdcmFile::WriteBase (std::string fileName, FileType type) {
    if ( (type == ImplicitVR) || (type == ExplicitVR) ) {
       char * filePreamble;
       // writing Dicom File Preamble
-      filePreamble=(char*)calloc(128,1);
+      filePreamble=new char[128];
       fwrite(filePreamble,128,1,fp1);
       fwrite("DICM",4,1,fp1);
-      free (filePreamble);
+      delete[] filePreamble;
    }
 
    // --------------------------------------------------------------
@@ -959,7 +959,7 @@ bool gdcmFile::ReadPixelData(void* destination) {
       
    if (ln != 0) {
       // What is it used for ?!?
-      char *BasicOffsetTableItemValue = (char *)malloc(ln+1);        
+      char *BasicOffsetTableItemValue = new char[ln+1];
       fread(BasicOffsetTableItemValue,ln,1,fp); 
    }
    
index 3b9528ed2fef1c8c22a7683fb866abc6366e7175..8c64575d0206035a021f58ba5603e4e33d0cbcd2 100644 (file)
@@ -631,7 +631,7 @@ unsigned char * gdcmHeader::GetLUTRGBA(void) {
    } 
    // forge the 4 * 8 Bits Red/Green/Blue/Alpha LUT 
    
-   unsigned char *LUTRGBA = (unsigned char *)calloc(1024,1); // 256 * 4 (R, G, B, Alpha) 
+   unsigned char *LUTRGBA = new (unsigned char)[1024]; // 256 * 4 (R, G, B, Alpha) 
    if (!LUTRGBA) {
       return NULL;
    }
index 241bd81856d7ea7a9f6f790b9a92529300d5dd3f..c7233f3026ff494a411ccaa4843935fb32e5fa31 100644 (file)
@@ -79,7 +79,7 @@ bool gdcmFile::ParsePixelData(void) {
             (unsigned)ftellRes,ln,ln);
       if (ln != 0) {
          // What is it used for ??
-         char * BasicOffsetTableItemValue= (char *)malloc(ln+1);
+         char * BasicOffsetTableItemValue= new char[ln+1];
          fread(BasicOffsetTableItemValue,ln,1,fp); 
          guint32 a;
          for (int i=0;i<ln;i+=4){
@@ -152,7 +152,7 @@ bool gdcmFile::ParsePixelData(void) {
             (unsigned)ftellRes,ln,ln);
       if (ln != 0) {
          // What is it used for ??
-         char * BasicOffsetTableItemValue= (char *)malloc(ln+1);
+         char * BasicOffsetTableItemValue= new char[ln+1];
          fread(BasicOffsetTableItemValue,ln,1,fp); 
          guint32 a;
          for (int i=0;i<ln;i+=4){
index 6cccb5a483cf9096737ab0a811018a68e5823393..7df4696954e9f1635a6488d7fe6b9ab1d38690d0 100644 (file)
@@ -753,7 +753,7 @@ void *gdcmParser::LoadEntryVoidArea(guint16 Group, guint16 Elem)
    size_t o =(size_t)Element->GetOffset();
    fseek(fp, o, SEEK_SET);
    size_t l=Element->GetLength();
-   void * a = malloc(l);
+   char* a = new char[l];
    if(!a) 
       return NULL;
 
@@ -762,7 +762,7 @@ void *gdcmParser::LoadEntryVoidArea(guint16 Group, guint16 Elem)
    size_t l2 = fread(a, 1, l ,fp);
    if(l != l2) 
    {
-      free(a);
+      delete[] a;
       return NULL;
    }
 
index 83a0c281cb64aed5ad86e53108c35a47f599666f..14f2431c5b465a0976d14c78facfcbcd9bda39e7 100644 (file)
@@ -41,7 +41,7 @@ bool gdcmFile::gdcm_read_RLE_file (FILE *fp,void * image_buffer) {
       ln=Header->SwapLong(ln);    // Basic Offset Table Item Lentgh
    if (ln != 0) {
       // What is it used for ??
-      char * BasicOffsetTableItemValue= (char *)malloc(ln+1);
+      char * BasicOffsetTableItemValue= new char[ln+1];
       fread(BasicOffsetTableItemValue,ln,1,fp); 
       guint32 a;
       for (int i=0;i<ln;i+=4){
@@ -114,7 +114,7 @@ bool gdcmFile::gdcm_read_RLE_file (FILE *fp,void * image_buffer) {
       int l = Header->GetXSize()*Header->GetYSize();
       int nbFrames = Header->GetZSize();
 
-      char * newDest = (char*) malloc(l*nbFrames*2);
+      char * newDest = new char[l*nbFrames*2];
       char *x  = newDest;
       char * a = (char *)image_buffer;
       char * b = a + l;
@@ -126,7 +126,7 @@ bool gdcmFile::gdcm_read_RLE_file (FILE *fp,void * image_buffer) {
          }
       }
       memmove(image_buffer,newDest,lgrTotale);
-      free(newDest);   
+      delete[] newDest;
    }
       
    return(true);