[mlpack] 175/207: use std::string to replace raw buffer, cpp11 guarantee memory layout is contiguous

Barak A. Pearlmutter barak+git at pearlmutter.net
Thu Mar 23 17:53:51 UTC 2017


This is an automated email from the git hooks/post-receive script.

bap pushed a commit to branch master
in repository mlpack.

commit c72cb2b5ce4bfb7aa74c9f737901825e716b7a36
Author: stereomatchingkiss <thamngapwei at gmail.com>
Date:   Sun Feb 19 11:49:15 2017 +0800

    use std::string to replace raw buffer, cpp11 guarantee memory layout is contiguous
---
 src/mlpack/core/data/load_impl.hpp | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/mlpack/core/data/load_impl.hpp b/src/mlpack/core/data/load_impl.hpp
index 123f12f..0d4d992 100644
--- a/src/mlpack/core/data/load_impl.hpp
+++ b/src/mlpack/core/data/load_impl.hpp
@@ -192,15 +192,16 @@ bool Load(const std::string& filename,
 
     // This is taken from load_auto_detect() in diskio_meat.hpp
     const std::string ARMA_MAT_TXT = "ARMA_MAT_TXT";
-    char* rawHeader = new char[ARMA_MAT_TXT.length() + 1];
+    //char* rawHeader = new char[ARMA_MAT_TXT.length() + 1];
+    std::string rawHeader(ARMA_MAT_TXT.length());
     std::streampos pos = stream.tellg();
 
-    stream.read(rawHeader, std::streamsize(ARMA_MAT_TXT.length()));
-    rawHeader[ARMA_MAT_TXT.length()] = '\0';
+    stream.read(&rawHeader[0], std::streamsize(ARMA_MAT_TXT.length()));
+    //rawHeader[ARMA_MAT_TXT.length()] = '\0';
     stream.clear();
     stream.seekg(pos); // Reset stream position after peeking.
 
-    if (std::string(rawHeader) == ARMA_MAT_TXT)
+    if (rawHeader == ARMA_MAT_TXT)
     {
       loadType = arma::arma_ascii;
       stringType = "Armadillo ASCII formatted data";
@@ -215,9 +216,7 @@ bool Load(const std::string& filename,
         stringType = "CSV data";
       else // Unknown .txt... we will throw an error.
         unknownType = true;
-    }
-
-    delete[] rawHeader;
+    }    
   }
   else if (extension == "bin")
   {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git



More information about the debian-science-commits mailing list