Home / Function/ calculateNewCapacity() — netty Function Reference

calculateNewCapacity() — netty Function Reference

Architecture documentation for the calculateNewCapacity() function in AbstractByteBufAllocator.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  7172b923_cb28_190b_8ff2_7986d51e1946["calculateNewCapacity()"]
  736a25f3_56bb_7053_ff2f_de4baf6ec402["AbstractByteBufAllocator"]
  7172b923_cb28_190b_8ff2_7986d51e1946 -->|defined in| 736a25f3_56bb_7053_ff2f_de4baf6ec402
  style 7172b923_cb28_190b_8ff2_7986d51e1946 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

buffer/src/main/java/io/netty/buffer/AbstractByteBufAllocator.java lines 231–259

    @Override
    public int calculateNewCapacity(int minNewCapacity, int maxCapacity) {
        checkPositiveOrZero(minNewCapacity, "minNewCapacity");
        if (minNewCapacity > maxCapacity) {
            throw new IllegalArgumentException(String.format(
                    "minNewCapacity: %d (expected: not greater than maxCapacity(%d)",
                    minNewCapacity, maxCapacity));
        }
        final int threshold = CALCULATE_THRESHOLD; // 4 MiB page

        if (minNewCapacity == threshold) {
            return threshold;
        }

        // If over threshold, do not double but just increase by threshold.
        if (minNewCapacity > threshold) {
            int newCapacity = minNewCapacity / threshold * threshold;
            if (newCapacity > maxCapacity - threshold) {
                newCapacity = maxCapacity;
            } else {
                newCapacity += threshold;
            }
            return newCapacity;
        }

        // 64 <= newCapacity is a power of 2 <= threshold
        final int newCapacity = MathUtil.findNextPositivePowerOfTwo(Math.max(minNewCapacity, 64));
        return Math.min(newCapacity, maxCapacity);
    }

Domain

Subdomains

Frequently Asked Questions

What does calculateNewCapacity() do?
calculateNewCapacity() is a function in the netty codebase, defined in buffer/src/main/java/io/netty/buffer/AbstractByteBufAllocator.java.
Where is calculateNewCapacity() defined?
calculateNewCapacity() is defined in buffer/src/main/java/io/netty/buffer/AbstractByteBufAllocator.java at line 231.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free