diff --git a/common/src/main/java/io/netty/util/internal/PlatformDependent.java b/common/src/main/java/io/netty/util/internal/PlatformDependent.java index c2b4270388..94f6294954 100644 --- a/common/src/main/java/io/netty/util/internal/PlatformDependent.java +++ b/common/src/main/java/io/netty/util/internal/PlatformDependent.java @@ -263,6 +263,16 @@ public final class PlatformDependent { return DIRECT_MEMORY_LIMIT; } + /** + * Returns the current memory reserved for direct buffer allocation. + * This method returns -1 in case that a value is not available. + * + * @see #maxDirectMemory() + */ + public static long usedDirectMemory() { + return DIRECT_MEMORY_COUNTER != null ? DIRECT_MEMORY_COUNTER.get() : -1; + } + /** * Returns the temporary directory. */