Exemplo n.º 1
0
    /**
     * Reallocate the specified block to the specified size.
     * \param b The block to be reallocated
     * \param n The new size
     * \return True, if the operation was successful.
     */
    bool reallocate(block &b, size_t n)
    {
      if (internal::reallocator<mallocator>::isHandledDefault(*this, b, n)) {
        return true;
      }

      block reallocatedBlock(::realloc(b.ptr, n), n);

      if (reallocatedBlock.ptr != nullptr) {
        b = reallocatedBlock;
        return true;
      }
      return false;
    }
      // On posix there is no _aligned_realloc so we try a normal realloc
      // if the result is still aligned we are fine
      // otherwise we have to do it by hand
      bool aligned_reallocate(block &b, size_t n) noexcept
      {
        block reallocatedBlock(::realloc(b.ptr, n));
        if (reallocatedBlock) {
          if (static_cast<size_t>(b.ptr) % alignment != 0) {
            auto newAlignedBlock = allocate(n);
            if (!newAlignedBlock) {
              return false;
            }
            internal::block_copy(b, newAlignedBlock);
          }
          else {
            b = reallocatedBlock;
          }

          return true;
        }
        return false;
      }