net.openhft.chronicle.bytes.Bytes.allocateDirect()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(2.8k)|赞(0)|评价(0)|浏览(80)

本文整理了Java中net.openhft.chronicle.bytes.Bytes.allocateDirect()方法的一些代码示例,展示了Bytes.allocateDirect()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytes.allocateDirect()方法的具体详情如下:
包路径:net.openhft.chronicle.bytes.Bytes
类名称:Bytes
方法名:allocateDirect

Bytes.allocateDirect介绍

[英]Allocate a fixed size buffer read for writing.
[中]分配一个固定大小的读写缓冲区。

代码示例

代码示例来源:origin: OpenHFT/Chronicle-Queue

@Test
public void testSimpleByteTest() {
  assumeFalse(Jvm.isArm());
  try (final ChronicleQueue chronicle = builder(getTmpDir(), wireType)
      .rollCycle(TEST2_DAILY)
      .build()) {
    final ExcerptAppender appender = chronicle.acquireAppender();
    Bytes steve = Bytes.allocateDirect("Steve".getBytes());
    appender.writeBytes(steve);
    Bytes jobs = Bytes.allocateDirect("Jobs".getBytes());
    appender.writeBytes(jobs);
    final ExcerptTailer tailer = chronicle.createTailer();
    Bytes bytes = Bytes.elasticByteBuffer();
    try {
      tailer.readBytes(bytes);
      Assert.assertEquals("Steve", bytes.toString());
      bytes.clear();
      tailer.readBytes(bytes);
      Assert.assertEquals("Jobs", bytes.toString());
    } finally {
      steve.release();
      jobs.release();
      bytes.release();
    }
  }
}

代码示例来源:origin: OpenHFT/Chronicle-Queue

@Test
public void testReadingLessBytesThanWritten() {
  try (final ChronicleQueue queue = builder(getTmpDir(), wireType)
      .build()) {
    final ExcerptAppender appender = queue.acquireAppender();
    final Bytes<byte[]> expected = Bytes.wrapForRead("some long message".getBytes(ISO_8859_1));
    for (int i = 0; i < 10; i++) {
      appender.writeBytes(expected);
    }
    final ExcerptTailer tailer = queue.createTailer();
    // Sequential read
    for (int i = 0; i < 10; i++) {
      Bytes b = Bytes.allocateDirect(8);
      tailer.readBytes(b);
      Assert.assertEquals(expected.readInt(0), b.readInt(0));
      b.release();
    }
  }
}

代码示例来源:origin: net.openhft/chronicle-bytes

/**
 * copies the contents of bytes into a direct byte buffer
 *
 * @param bytes the bytes to wrap
 * @return a direct byte buffer contain the {@code bytes}
 */
@NotNull
static Bytes allocateDirect(@NotNull byte[] bytes) throws IllegalArgumentException {
  Bytes<Void> result = allocateDirect(bytes.length);
  try {
    result.write(bytes);
  } catch (BufferOverflowException e) {
    throw new AssertionError(e);
  }
  return result;
}

代码示例来源:origin: peter-lawrey/Performance-Examples

private static void testBytes() {
    Bytes bytes = Bytes.allocateDirect(32);
    long start = System.currentTimeMillis();
    int count = 500000;
    for (int i = 0; i < count; i++) {
      bytes.clear();
      String s = "a,b,c,d,1,2,3,4";
      bytes.append8bit(s);
      a = bytes.parseUtf8(StopCharTesters.COMMA_STOP);
      b = bytes.parseUtf8(StopCharTesters.COMMA_STOP);
      c = bytes.parseUtf8(StopCharTesters.COMMA_STOP);
      d = bytes.parseUtf8(StopCharTesters.COMMA_STOP);
      e = (int) bytes.parseLong();
      f = (int) bytes.parseLong();
      g = (int) bytes.parseLong();
      h = (int) bytes.parseLong();
    }
    long time = (System.currentTimeMillis() - start) * 100000 / count;
    System.out.println("Bytes: Average time " + time / 1e2 + "us.");
  }
}

相关文章

微信公众号

最新文章

更多