[Liblas-commits] hg: use a simple stack-allocated vector instead of maintaining a...

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Sep 23 12:26:05 EDT 2010


changeset 6911043b85cc in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=6911043b85cc
summary: use a simple stack-allocated vector instead of maintaining a heap-allocated array to manage writing blanks into point records

diffstat:

 include/liblas/detail/writer/point.hpp |   4 +++-
 src/detail/writer/point.cpp            |  14 +++++---------
 2 files changed, 8 insertions(+), 10 deletions(-)

diffs (73 lines):

diff -r 37f78228542a -r 6911043b85cc include/liblas/detail/writer/point.hpp
--- a/include/liblas/detail/writer/point.hpp	Thu Sep 23 09:39:16 2010 -0500
+++ b/include/liblas/detail/writer/point.hpp	Thu Sep 23 11:25:49 2010 -0500
@@ -50,8 +50,10 @@
 #include <liblas/detail/fwd.hpp>
 // boost
 #include <boost/cstdint.hpp>
+
 // std
 #include <iosfwd>
+#include <vector>
 
 namespace liblas { namespace detail { namespace writer {
 
@@ -86,7 +88,7 @@
     
     Schema m_format;
     
-    boost::uint8_t* m_blanks; // TODO: shared_ptr --mlosko
+    std::vector<boost::uint8_t> m_blanks; 
 
     bool bTime;
     bool bColor;
diff -r 37f78228542a -r 6911043b85cc src/detail/writer/point.cpp
--- a/src/detail/writer/point.cpp	Thu Sep 23 09:39:16 2010 -0500
+++ b/src/detail/writer/point.cpp	Thu Sep 23 11:25:49 2010 -0500
@@ -61,7 +61,6 @@
     , m_header(header)
     , m_point(liblas::Point())
     , m_format(header.GetSchema())
-    , m_blanks(0)
     , bTime(header.GetSchema().HasTime())
     , bColor(header.GetSchema().HasColor())
 {
@@ -70,8 +69,7 @@
 
 Point::~Point()
 {
-    if (m_blanks != 0) 
-        delete[] m_blanks; 
+
 }
 
 void Point::setup()
@@ -89,10 +87,8 @@
             throw std::runtime_error("ByteSize of format was less than BaseByteSize, this cannot happen!");
         }
         
-        m_blanks = new uint8_t[size]; // FIXME: RAII for m_blanks!!! --mloskot
-        for (std::size_t i=0; i < size; ++i) {
-            m_blanks[i] = 0;
-        }
+        m_blanks.resize(size);
+        m_blanks.assign(size, 0);
     }
 }
 
@@ -162,13 +158,13 @@
         
         if (data.size() == 0) {
 
-            detail::write_n(GetStream(), *m_blanks, static_cast<std::streamsize>(size));
+            detail::write_n(GetStream(), m_blanks.front(), static_cast<std::streamsize>(size));
             
         } else if (data.size() < size){ 
             // size can be casted now that we have already checked if it is less than 0
             int16_t difference = static_cast<uint16_t>(size) - static_cast<uint16_t>(data.size());
             detail::write_n(GetStream(), data.front(), data.size());
-            detail::write_n(GetStream(), *m_blanks, static_cast<std::streamsize>(difference));
+            detail::write_n(GetStream(), m_blanks.front(), static_cast<std::streamsize>(difference));
 
         } else {
             detail::write_n(GetStream(), data.front(), static_cast<std::streamsize>(size));


More information about the Liblas-commits mailing list