use of net.openhft.chronicle.core.Memory in project Chronicle-Queue by OpenHFT.
the class InternalBenchmarkMain method writeMessage.
private static void writeMessage(Wire wire, int messageSize) {
Bytes<?> bytes = wire.bytes();
long wp = bytes.writePosition();
long addr = bytes.addressForWrite(wp);
Memory memory = OS.memory();
for (int i = 0; i < messageSize; i += 16) {
memory.writeLong(addr + i, 0L);
memory.writeLong(addr + i + 8, 0L);
}
bytes.writeSkip(messageSize);
bytes.writeLong(wp, System.nanoTime());
}
use of net.openhft.chronicle.core.Memory in project Chronicle-Bytes by OpenHFT.
the class VanillaBytes method isEqual0.
private static boolean isEqual0(@NotNull char[] chars, @NotNull NativeBytesStore bs, long address) {
@Nullable Memory memory = bs.memory;
int i = 0;
for (; i < chars.length - 3; i += 4) {
int b = memory.readInt(address + i);
int b0 = b & 0xFF;
int b1 = (b >> 8) & 0xFF;
int b2 = (b >> 16) & 0xFF;
int b3 = (b >> 24) & 0xFF;
if (b0 != chars[i] || b1 != chars[i + 1] || b2 != chars[i + 2] || b3 != chars[i + 3])
return false;
}
for (; i < chars.length; i++) {
int b = memory.readByte(address + i) & 0xFF;
if (b != chars[i])
return false;
}
return true;
}
use of net.openhft.chronicle.core.Memory in project Chronicle-Bytes by OpenHFT.
the class NativeBytesStore method write8bit.
void write8bit(long position, char[] chars, int offset, int length) {
long addr = address + translate(position);
@Nullable Memory memory = this.memory;
for (int i = 0; i < length; i++) memory.writeByte(addr + i, (byte) chars[offset + i]);
}
use of net.openhft.chronicle.core.Memory in project Chronicle-Bytes by OpenHFT.
the class NativeBytesStore method read8bit.
void read8bit(long position, char[] chars, int length) {
long addr = address + translate(position);
Memory memory = OS.memory();
for (int i = 0; i < length; i++) chars[i] = (char) (memory.readByte(addr + i) & 0xFF);
}
use of net.openhft.chronicle.core.Memory in project Chronicle-Bytes by OpenHFT.
the class NativeBytesStore method appendUtf8.
public long appendUtf8(long pos, char[] chars, int offset, int length) throws BufferOverflowException {
if (pos + length > realCapacity())
throw new BufferOverflowException();
long address = this.address + translate(0);
@Nullable Memory memory = this.memory;
if (memory == null)
throw new NullPointerException();
Unsafe unsafe = UnsafeMemory.UNSAFE;
int i;
ascii: {
for (i = 0; i < length - 3; i += 4) {
final int i2 = offset + i;
char c0 = chars[i2];
char c1 = chars[i2 + 1];
char c2 = chars[i2 + 2];
char c3 = chars[i2 + 3];
if ((c0 | c1 | c2 | c3) > 0x007F)
break ascii;
final int value = (c0) | (c1 << 8) | (c2 << 16) | (c3 << 24);
unsafe.putInt(address + pos, value);
pos += 4;
}
for (; i < length; i++) {
char c = chars[offset + i];
if (c > 0x007F)
break ascii;
unsafe.putByte(address + pos++, (byte) c);
}
return pos;
}
return appendUtf8a(pos, chars, offset, length, i);
}
Aggregations