/** * Create a pooled ByteBuf allocator but disables the thread-local cache. Thread-local caches * are disabled for TransportClients because the ByteBufs are allocated by the event loop thread, * but released by the executor thread rather than the event loop thread. Those thread-local * caches actually delay the recycling of buffers, leading to larger memory usage. */ public static PooledByteBufAllocator createPooledByteBufAllocator( boolean allowDirectBufs, boolean allowCache, int numCores) { if (numCores == 0) { numCores = Runtime.getRuntime().availableProcessors(); } return new PooledByteBufAllocator( allowDirectBufs && PlatformDependent.directBufferPreferred(), Math.min(getPrivateStaticField("DEFAULT_NUM_HEAP_ARENA"), numCores), Math.min(getPrivateStaticField("DEFAULT_NUM_DIRECT_ARENA"), allowDirectBufs ? numCores : 0), getPrivateStaticField("DEFAULT_PAGE_SIZE"), getPrivateStaticField("DEFAULT_MAX_ORDER"), allowCache ? getPrivateStaticField("DEFAULT_TINY_CACHE_SIZE") : 0, allowCache ? getPrivateStaticField("DEFAULT_SMALL_CACHE_SIZE") : 0, allowCache ? getPrivateStaticField("DEFAULT_NORMAL_CACHE_SIZE") : 0 ); }
/** * Create a pooled ByteBuf allocator but disables the thread-local cache. Thread-local caches * are disabled for TransportClients because the ByteBufs are allocated by the event loop thread, * but released by the executor thread rather than the event loop thread. Those thread-local * caches actually delay the recycling of buffers, leading to larger memory usage. */ public static PooledByteBufAllocator createPooledByteBufAllocator( boolean allowDirectBufs, boolean allowCache, int numCores) { if (numCores == 0) { numCores = Runtime.getRuntime().availableProcessors(); } return new PooledByteBufAllocator( allowDirectBufs && PlatformDependent.directBufferPreferred(), Math.min(getPrivateStaticField("DEFAULT_NUM_HEAP_ARENA"), numCores), Math.min(getPrivateStaticField("DEFAULT_NUM_DIRECT_ARENA"), allowDirectBufs ? numCores : 0), getPrivateStaticField("DEFAULT_PAGE_SIZE"), getPrivateStaticField("DEFAULT_MAX_ORDER"), allowCache ? getPrivateStaticField("DEFAULT_TINY_CACHE_SIZE") : 0, allowCache ? getPrivateStaticField("DEFAULT_SMALL_CACHE_SIZE") : 0, allowCache ? getPrivateStaticField("DEFAULT_NORMAL_CACHE_SIZE") : 0 ); }