Index: trunk/Mars/mcore/zofits.h
===================================================================
--- trunk/Mars/mcore/zofits.h	(revision 17253)
+++ trunk/Mars/mcore/zofits.h	(revision 17254)
@@ -37,4 +37,5 @@
         };
 
+
         //catalog types
         struct CatalogEntry
@@ -42,9 +43,11 @@
             CatalogEntry(int64_t f=0, int64_t s=0) : first(f), second(s) {};
             int64_t first;   ///< Size of this column in the tile
-            int64_t second; ///< offset of this column in the tile, from the start of the heap area
+            int64_t second;  ///< offset of this column in the tile, from the start of the heap area
         } __attribute__((__packed__));
+
         typedef vector<CatalogEntry> CatalogRow;
         typedef list<CatalogRow>     CatalogType;
 
+
         /// Parameters required to write a tile to disk
         struct WriteTarget
@@ -55,8 +58,9 @@
             }
 
-            uint32_t                tile_num; ///< Tile index of the data (to make sure that they are written in the correct order)
-            uint32_t                size;    ///<  Size to write
-            shared_ptr<MemoryChunk> data;   ///<   Memory block to write
+            uint32_t         tile_num; ///< Tile index of the data (to make sure that they are written in the correct order)
+            uint32_t         size;     ///< Size to write
+            shared_ptr<char> data;     ///<  Memory block to write
         };
+
 
         /// Parameters required to compress a tile of data
@@ -66,9 +70,9 @@
             {}
 
-            CatalogRow&             catalog_entry;   ///< Reference to the catalog entry to deal with
-            shared_ptr<MemoryChunk> src;            ///<  Original data
-            shared_ptr<MemoryChunk> transposed_src;///<   Transposed data
-            WriteTarget             target;       ///<    Compressed data
-            uint32_t                num_rows;    ///<     Number of rows to compress
+            CatalogRow&      catalog_entry;   ///< Reference to the catalog entry to deal with
+            shared_ptr<char> src;             ///< Original data
+            shared_ptr<char> transposed_src;  ///< Transposed data
+            WriteTarget      target;          ///< Compressed data
+            uint32_t         num_rows;        ///< Number of rows to compress
          };
 
@@ -124,5 +128,4 @@
             fNumRowsPerTile = rpt;
 
-            fBuffer           = NULL;
             fRealRowWidth     = 0;
             fCatalogOffset    = 0;
@@ -273,5 +276,5 @@
 
             //copy current row to pool or rows waiting for compression
-            char* target_location = fBuffer + fRealRowWidth*(fTable.num_rows%fNumRowsPerTile);
+            char* target_location = fSmartBuffer.get() + fRealRowWidth*(fTable.num_rows%fNumRowsPerTile);
             memcpy(target_location, ptr, fRealRowWidth);
 
@@ -309,5 +312,5 @@
                 if (fNumQueues == 0)
                 { //no worker threads. do everything in-line
-                    uint64_t size_to_write = CompressBuffer(compress_target);
+                    const uint64_t size_to_write = CompressBuffer(compress_target);
 
                     WriteTarget write_target;
@@ -325,5 +328,5 @@
                      uint32_t current_index = 0;
 
-                     for (auto it=fCompressionQueues.begin(); it!=fCompressionQueues.end(); it++)
+                     for (auto it=fCompressionQueues.cbegin(); it!=fCompressionQueues.cend(); it++)
                      {
                          if (it->size() < min_size)
@@ -356,5 +359,5 @@
         {
             //get space for transposed data
-            shared_ptr<MemoryChunk> transposed_data = fMemPool.malloc();
+            shared_ptr<char> transposed_data = fMemPool.malloc();
 
             //fill up write to disk target
@@ -372,5 +375,4 @@
             //get a new buffer to host the incoming data
             fSmartBuffer = fMemPool.malloc();
-            fBuffer      = fSmartBuffer.get()->get();
         }
 
@@ -625,6 +627,4 @@
 
             fSmartBuffer = fMemPool.malloc();
-            fBuffer      = fSmartBuffer.get()->get();
-
             fRawSumBuffer.resize(fRealRowWidth + 4-fRealRowWidth%4); //for checksuming
         }
@@ -686,8 +686,8 @@
 #endif
                 //transpose the original data
-                copyTransposeTile(target.src.get()->get(), target.transposed_src.get()->get());
+                copyTransposeTile(target.src.get(), target.transposed_src.get());
 
                 //compress the buffer
-                compressed_size = compressBuffer(target.target.data.get()->get(), target.transposed_src.get()->get(), target.num_rows, target.catalog_entry);
+                compressed_size = compressBuffer(target.target.data.get(), target.transposed_src.get(), target.num_rows, target.catalog_entry);
 #ifdef __EXCEPTIONS
             }
@@ -730,5 +730,5 @@
             {
 #endif
-                if (!writeCompressedDataToDisk(target.data.get()->get(), target.size))
+                if (!writeCompressedDataToDisk(target.data.get(), target.size))
                 {//could not write the data to disk
                     ostringstream str;
@@ -990,8 +990,7 @@
         };
         vector<CompressedColumn> fRealColumns;     ///< Vector hosting the columns of the file
-        uint32_t                 fRealRowWidth;   ///<  Width in bytes of one uncompressed row
-        shared_ptr<MemoryChunk>  fSmartBuffer;   ///<   Smart pointer to the buffer where the incoming rows are written
-        char*                    fBuffer;       ///<    regular version of fSmartBuffer
-        vector<char>             fRawSumBuffer;///<     buffer used for checksuming the incoming data, before compression
+        uint32_t                 fRealRowWidth;    ///< Width in bytes of one uncompressed row
+        shared_ptr<char>         fSmartBuffer;     ///< Smart pointer to the buffer where the incoming rows are written
+        vector<char>             fRawSumBuffer;    ///< buffer used for checksuming the incoming data, before compression
 
 #ifdef __EXCEPTIONS
