package edu.uci.ics.hyracks.control.nc.resources.memory;

import java.util.concurrent.atomic.AtomicLong;

import edu.uci.ics.hyracks.api.resources.memory.IMemoryManager;

public class MemoryManager implements IMemoryManager {
    private final long maxMemory;

    private final AtomicLong memory;

    public MemoryManager(long maxMemory) {
        this.maxMemory = maxMemory;
        this.memory = new AtomicLong(maxMemory);
    }

    @Override
    public long getMaximumMemory() {
        return maxMemory;
    }

    @Override
    public long getAvailableMemory() {
        return memory.get();
    }

    @Override
    public boolean allocate(long memory) {
        if (this.memory.addAndGet(-memory) < 0) {
            this.memory.addAndGet(memory);
            return false;
        }
        return true;
    }

    @Override
    public void deallocate(long memory) {
        this.memory.addAndGet(memory);
    }
}
@@ -649,32 +649,111 @@
 (long memory) %7B%0A
+        // commented as now the deallocation is not implemented yet.%0A        //
         if (this
@@ -782,24 +782,34 @@
 ory) %3C 0) %7B%0A
+        //
             
@@ -838,24 +838,31 @@
 memory);%0A   
+     //
          ret
@@ -854,24 +854,27 @@
  //         
+   
 return false
@@ -875,16 +875,26 @@
  false;%0A
+        //
         

disable the memory manager counter