Changeset 17250 for trunk


Ignore:
Timestamp:
10/18/13 13:28:43 (11 years ago)
Author:
tbretz
Message:
Updated exception handling to make Mars happy.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Mars/mcore/MemoryManager.h

    r17219 r17250  
    2121
    2222public:
    23     MemoryStock(size_t chunk, size_t max) : fChunkSize(chunk), fMaxMemory(max),
     23    MemoryStock(size_t chunk, size_t max) : fChunkSize(chunk), fMaxMemory(max<chunk?chunk:max),
    2424        fInUse(0), fAllocated(0), fMaxInUse(0)
    2525    {
    26         if (chunk>max)
    27             throw std::runtime_error("Size mismatch: Size of a single chunk exceeds maximum size of memory");
    2826    }
    2927
     
    138136
    139137    size_t getChunkSize() const { return fMemoryStock->fChunkSize; }
    140     void   setChunkSize(const size_t size)
     138    bool   setChunkSize(const size_t size)
    141139    {
    142         if (getInUse() != 0)
     140#ifdef __EXCEPTIONS
     141        if (getInUse())
    143142            throw std::runtime_error("Cannot change the chunk size while there is memory in use");
     143        if (getMaxMemory()<size)
     144            throw std::runtime_error("Chunk size("+to_string(size)+") larger thann allowed memory ("+to_string(getMaxMemory())+")");
     145#else
     146        if (getInUse() || getMaxMemory()<size)
     147            return false;
    144148
    145         if (getMaxMemory() < size)
    146         {
    147             std::ostringstream str;
    148             str << "Chunk size(" << size << ") larger thank allowed memory(" << getMaxMemory() << "). Cannot allocate a single chunk.";
    149             throw std::runtime_error(str.str());
    150         }
    151149        fMemoryStock->fChunkSize = size;
     150        return true;
    152151    }
     152
    153153    size_t getMaxMemory() const { return fMemoryStock->fMaxMemory; }
    154154    size_t getInUse() const { return fMemoryStock->fInUse; }
Note: See TracChangeset for help on using the changeset viewer.