-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Mnemonic infra. as an alternative backed allocation mechanism, …
…note that move allocator services to the service-dist folder as the properties indicated in pom.xml.
- Loading branch information
Wang, Gang(Gary)
committed
Oct 25, 2017
1 parent
8148b6d
commit 9e59d4e
Showing
10 changed files
with
3,580 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,5 @@ cpp/.idea/ | |
python/.eggs/ | ||
.vscode | ||
.idea/ | ||
java/memory/base_allocator_test.dat | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
java/memory/src/main/java/io/netty/buffer/MnemonicUnpooledByteBufAllocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2012 The Netty Project | ||
* | ||
* The Netty Project licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package io.netty.buffer; | ||
|
||
import io.netty.util.internal.PlatformDependent; | ||
|
||
import org.apache.mnemonic.CommonAllocator; | ||
|
||
/** | ||
* Simplistic {@link ByteBufAllocator} implementation that does not pool anything. | ||
*/ | ||
public final class MnemonicUnpooledByteBufAllocator<A extends CommonAllocator<A>> extends AbstractByteBufAllocator { | ||
|
||
private A mcalloc; | ||
|
||
/** | ||
* Default instance | ||
*/ | ||
// public static final UnpooledByteBufAllocator DEFAULT = | ||
// new UnpooledByteBufAllocator(PlatformDependent.directBufferPreferred()); | ||
|
||
/** | ||
* Create a new instance | ||
* | ||
* @param preferDirect {@code true} if {@link #buffer(int)} should try to allocate a direct buffer rather than | ||
* a heap buffer | ||
*/ | ||
public MnemonicUnpooledByteBufAllocator(boolean preferDirect, A mcallocator) { | ||
super(preferDirect); | ||
this.mcalloc = mcallocator; | ||
} | ||
|
||
public A getAllocator() { | ||
return this.mcalloc; | ||
} | ||
|
||
@Override | ||
protected ByteBuf newHeapBuffer(int initialCapacity, int maxCapacity) { | ||
return new UnpooledHeapByteBuf(this, initialCapacity, maxCapacity); | ||
} | ||
|
||
@Override | ||
protected ByteBuf newDirectBuffer(int initialCapacity, int maxCapacity) { | ||
assert null != this.mcalloc; | ||
ByteBuf buf; | ||
if (PlatformDependent.hasUnsafe()) { | ||
buf = new MnemonicUnpooledUnsafeDirectByteBuf<A>(this, initialCapacity, maxCapacity); | ||
} else { | ||
buf = new MnemonicUnpooledDirectByteBuf<A>(this, initialCapacity, maxCapacity); | ||
} | ||
|
||
return toLeakAwareBuffer(buf); | ||
} | ||
|
||
@Override | ||
public boolean isDirectBufferPooled() { | ||
return false; | ||
} | ||
} |
Oops, something went wrong.