public SerializingQueue(final AbstractInvokable task) {
    memoryManager = task.getEnvironment().getMemoryManager();
    allocatingIterator =
        new Iterator<MemorySegment>() {
          @Override
          public boolean hasNext() {
            return true;
          }

          @Override
          public MemorySegment next() {
            try {
              return memoryManager.allocateStrict(task, 1, DEFAULT_MEMORY_SEGMENT_SIZE).get(0);
            } catch (Exception ex) {
              throw new RuntimeException("Bad error during serialization", ex);
            }
          }

          @Override
          public void remove() {}
        };

    currentWriteSegment = allocatingIterator.next();
    currentReadSegment = currentWriteSegment;
    segments.add(currentWriteSegment);
  }
 protected AbstractSingleGateRecordReader(AbstractInvokable invokable) {
   this.inputGate = invokable.getEnvironment().createAndRegisterInputGate();
 }