[Libreoffice-commits] core.git: 2 commits - sc/inc sc/source

Eike Rathke erack at redhat.com
Mon Oct 23 14:17:43 UTC 2017


 sc/inc/scmatrix.hxx              |   17 ---------------
 sc/source/core/tool/scmatrix.cxx |   44 +++++++++++++++++++++++++++++++++++++--
 2 files changed, 42 insertions(+), 19 deletions(-)

New commits:
commit ad2f1d2675ce480abf06db280fc551372b3cbed3
Author: Eike Rathke <erack at redhat.com>
Date:   Mon Oct 23 16:15:49 2017 +0200

    Assume 6GB memory could be consumed by matrices
    
    ... if SC_MAX_MATRIX_ELEMENTS is not set.
    
    Change-Id: I27100d5fc75e2d5288892c54997147854de781e7

diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index 9fa822fad412..32dc362245bd 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -339,13 +339,23 @@ private:
 static bool bElementsMaxFetched;
 static size_t nElementsMax;
 
-/// The maximum number of elements a matrix may have at runtime.
-static size_t GetElementsMax()
+/** The maximum number of elements a matrix or the pool may have at runtime.
+
+    @param  nMemory
+            If 0, the arbitrary limit of one matrix is returned.
+            If >0, the given memory pool divided by the average size of a
+            matrix element is returned, which is used to initialize
+            nElementsMax.
+ */
+static size_t GetElementsMax( size_t nMemory )
 {
     // Arbitrarily assuming 12 bytes per element, 8 bytes double plus
     // overhead. Stored as an array in an mdds container it's less, but for
     // strings or mixed matrix it can be much more..
     constexpr size_t nPerElem = 12;
+    if (nMemory)
+        return nMemory / nPerElem;
+
     // Arbitrarily assuming 1GB memory. Could be dynamic at some point.
     constexpr size_t nMemMax = 0x40000000;
     // With 1GB that's ~85M elements, or 85 whole columns.
@@ -2797,8 +2807,21 @@ bool ScMatrix::IsSizeAllocatable( SCSIZE nC, SCSIZE nR )
 
     if (!bElementsMaxFetched)
     {
-        nElementsMax = std::getenv("SC_MAX_MATRIX_ELEMENTS") ? std::atoi(std::getenv("SC_MAX_MATRIX_ELEMENTS"))
-                                                                       : GetElementsMax();
+        const char* pEnv = std::getenv("SC_MAX_MATRIX_ELEMENTS");
+        if (pEnv)
+        {
+            // Environment specifies the overall elements pool.
+            nElementsMax = std::atoi(pEnv);
+        }
+        else
+        {
+            // GetElementsMax() uses an (~arbitrary) elements limit.
+            // Assume 6GB memory could be consumed by matrices.
+            // The actual allocation depends on the types of individual matrix
+            // elements and is averaged for type double.
+            constexpr size_t nMemMax = 0x180000000;
+            nElementsMax = GetElementsMax( nMemMax);
+        }
         bElementsMaxFetched = true;
     }
 
commit 443113383296ca4781fb44e58e018a337db8e73c
Author: Eike Rathke <erack at redhat.com>
Date:   Mon Oct 23 15:12:22 2017 +0200

    Move GetElementsMax() to .cxx
    
    Nothing else is using it so we don't need it in .hxx
    
    Change-Id: I0df879a7be2c56a70c30f50f44a92bb527b5a9ed

diff --git a/sc/inc/scmatrix.hxx b/sc/inc/scmatrix.hxx
index c80ce3333ab0..4acd2c937f91 100644
--- a/sc/inc/scmatrix.hxx
+++ b/sc/inc/scmatrix.hxx
@@ -152,23 +152,6 @@ public:
             mfFirst(r.mfFirst), mfRest(r.mfRest), mnCount(r.mnCount) {}
     };
 
-    /// The maximum number of elements a matrix may have at runtime.
-    static size_t GetElementsMax()
-    {
-        // Arbitrarily assuming 12 bytes per element, 8 bytes double plus
-        // overhead. Stored as an array in an mdds container it's less, but for
-        // strings or mixed matrix it can be much more..
-        constexpr size_t nPerElem = 12;
-        // Arbitrarily assuming 1GB memory. Could be dynamic at some point.
-        constexpr size_t nMemMax = 0x40000000;
-        // With 1GB that's ~85M elements, or 85 whole columns.
-        constexpr size_t nElemMax = nMemMax / nPerElem;
-        // With MAXROWCOUNT==1048576 and 128 columns => 128M elements, 1.5GB
-        constexpr size_t nArbitraryLimit = (size_t)MAXROWCOUNT * 128;
-        // With the constant 1GB from above that's the actual value.
-        return nElemMax < nArbitraryLimit ? nElemMax : nArbitraryLimit;
-    }
-
     /** Checks nC or nR for zero and uses GetElementsMax() whether a matrix of
         the size of nC*nR could be allocated. A zero size (both nC and nR zero)
         matrix is allowed for later resize.
diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index 7df5dbe52793..9fa822fad412 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -339,6 +339,23 @@ private:
 static bool bElementsMaxFetched;
 static size_t nElementsMax;
 
+/// The maximum number of elements a matrix may have at runtime.
+static size_t GetElementsMax()
+{
+    // Arbitrarily assuming 12 bytes per element, 8 bytes double plus
+    // overhead. Stored as an array in an mdds container it's less, but for
+    // strings or mixed matrix it can be much more..
+    constexpr size_t nPerElem = 12;
+    // Arbitrarily assuming 1GB memory. Could be dynamic at some point.
+    constexpr size_t nMemMax = 0x40000000;
+    // With 1GB that's ~85M elements, or 85 whole columns.
+    constexpr size_t nElemMax = nMemMax / nPerElem;
+    // With MAXROWCOUNT==1048576 and 128 columns => 128M elements, 1.5GB
+    constexpr size_t nArbitraryLimit = (size_t)MAXROWCOUNT * 128;
+    // With the constant 1GB from above that's the actual value.
+    return nElemMax < nArbitraryLimit ? nElemMax : nArbitraryLimit;
+}
+
 ScMatrixImpl::ScMatrixImpl(SCSIZE nC, SCSIZE nR) :
     maMat(nR, nC), maMatFlag(nR, nC), pErrorInterpreter(nullptr)
 {
@@ -2781,7 +2798,7 @@ bool ScMatrix::IsSizeAllocatable( SCSIZE nC, SCSIZE nR )
     if (!bElementsMaxFetched)
     {
         nElementsMax = std::getenv("SC_MAX_MATRIX_ELEMENTS") ? std::atoi(std::getenv("SC_MAX_MATRIX_ELEMENTS"))
-                                                                       : ScMatrix::GetElementsMax();
+                                                                       : GetElementsMax();
         bElementsMaxFetched = true;
     }
 


More information about the Libreoffice-commits mailing list