Commits

Sam Preston committed 5d89748 Merge

Merge branch 'master' of ssh://bitbucket.org/scicompanat/pyca

Comments (0)

Files changed (2)

Code/Cxx/inc/base/MemoryManager.h

   public:
     // Constructor that either calls ThreadMemoryManager or creates an Image3D
     ManagedImage3D(const GridInfo& grid, MemoryType mType);
+    ManagedImage3D(const GridInfo& grid, MemoryType mType, MemoryManager& mm);
 
     ~ManagedImage3D();  // Just a hook to release from the mm
 
   public:
     // Constructor that either calls ThreadMemoryManager or creates an Field3D
     ManagedField3D(const GridInfo& grid, MemoryType mType);
+    ManagedField3D(const GridInfo& grid, MemoryType mType, MemoryManager& mm);
 
     ~ManagedField3D();  // Just a hook to release from the mm
 

Code/Cxx/src/base/MemoryManager.cxx

 #include <Image3D.h>
 #include <Field3D.h>
 #include <MemoryManager.h>
+#include "PyCAException.h"
 
 namespace PyCA {
 
     setGrid(g);  // have to use the public accessor here
 }
 
+ManagedImage3D::ManagedImage3D(const GridInfo& g, MemoryType mt, MemoryManager &mm)
+    : Image3D(mt) {
+    if (mm.memType() != mt) {  // can't use mm so don't manage
+        throw PyCAException(__FILE__, __LINE__, "MemoryManager memType does not match");
+    }
+
+    // if types are compatible go ahead and use the mm
+    boost::shared_ptr<MemPool<float> > p;
+    mManager = &mm;
+    mId = mm.getPool(g, p);
+    mData = MemPool<float>(p->getSharedPtr(), g.nVox(), mt);
+
+    setGrid(g);  // have to use the public accessor here
+}
+
 ManagedImage3D::~ManagedImage3D() {
     if (mManager) {  // This image is being managed, release it
         mManager->releasePool(mId);
     setGrid(g);  // have to use the public accessor here
 }
 
+ManagedField3D::ManagedField3D(const GridInfo& g, MemoryType mt, MemoryManager& mm)
+    : Field3D(mt) {
+    if (mm.memType() != mt) {  // can't use mm so don't manage
+        throw PyCAException(__FILE__, __LINE__, "MemoryManager memType does not match");
+    }
+    boost::shared_ptr<MemPool<float> > p;
+    mManager = &mm;
+    mIdX = mm.getPool(g, p);
+    mDataX = MemPool<float>(p->getSharedPtr(), g.nVox(), mt);
+    mIdY = mm.getPool(g, p);
+    mDataY = MemPool<float>(p->getSharedPtr(), g.nVox(), mt);
+    mIdZ = mm.getPool(g, p);
+    mDataZ = MemPool<float>(p->getSharedPtr(), g.nVox(), mt);
+
+    setGrid(g);  // have to use the public accessor here
+}
+
 ManagedField3D::~ManagedField3D() {
     if (mManager) {  // This image is being managed, release it
         mManager->releasePool(mIdX);