congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
DirectBytes
Code IndexAdd Tabnine to your IDE (free)

How to use
DirectBytes
in
net.openhft.lang.io

Best Java code snippets using net.openhft.lang.io.DirectBytes (Showing top 20 results out of 315)

origin: OpenHFT/Java-Lang

@NotNull
public final DirectBytes bytes() {
  return new DirectBytes(this, refCount);
}
origin: stackoverflow.com

 final DirectStore store = DirectStore.allocate(128L << 32); // give me 128 GB
final DirectBytes slice = store.createSlice();

// every record has say 128 bytes and a lock at the start so they can be locked individually
for(long l = 0; l < store.size(); l += 128) {
  slice.positionAndSize(l, 128);
  slice.busyLock(0L);
  // change something
  slive.writeLong(4L, l);
  slice.unlock(0L);
}

// when finished with the store
store.free(); // still no GCs.
origin: net.openhft/lang

static void writeUTF1(DirectBytes bytes, @NotNull char[] chars, int strlen) {
  int i;
  ascii:
  {
    for (i = 0; i < strlen; i++) {
      char c = chars[i];
      if (c > 0x007F)
        break ascii;
      NativeBytes.UNSAFE.putByte(bytes.positionAddr + i, (byte) c);
    }
    bytes.skip(i);
    return;
  }
  bytes.skip(i);
  if (i < strlen)
    writeUTF2(bytes, chars, strlen, i);
}
origin: OpenHFT/Java-Lang

@Override
public T get(long index) {
  T t = acquire();
  Byteable byteable = (Byteable) t;
  DirectBytes bytes = (DirectBytes) byteable.bytes();
  bytes.positionAndSize(index * size, size);
  return t;
}
origin: net.openhft/lang

public void positionAndSize(long offset, long size) {
  if (offset < 0 || size < 0 || offset + size > store.size())
    throw new IllegalArgumentException();
  setStartPositionAddress(store.address() + offset);
  capacityAddr = limitAddr = startAddr + size;
}
origin: net.openhft/lang

  @Override
  public ByteBuffer sliceAsByteBuffer(ByteBuffer toReuse) {
    return sliceAsByteBuffer(toReuse, store);
  }
}
origin: net.openhft/lang

  @Override
  public void recycle(T t) {
    if (freeList.size() < MAX_SIZE) {
      assert ((DirectBytes) ((Byteable) t).bytes()).store() == store;
      assert !freeList.contains(t) : "recycling object already recycled";
      freeList.add(t);
    }
  }
}
origin: peter-lawrey/Performance-Examples

  public static void main(String... ignored) throws IOException {
    // this example only works on Linux
    File file = new File("/tmp/shared");
    MappedStore ms = new MappedStore(file, FileChannel.MapMode.READ_WRITE, 64L << 40);
    DirectBytes bytes = ms.bytes();
//        bytes.writeLong(0L, 1234);
    System.out.println("value=" + bytes.readLong(0L));
    long end = System.currentTimeMillis() + 30 * 1000;
    while (end > System.currentTimeMillis()) ;
    ms.free();
  }
}
origin: net.openhft/lang

@Override
public T get(long index) {
  T t = acquire();
  Byteable byteable = (Byteable) t;
  DirectBytes bytes = (DirectBytes) byteable.bytes();
  bytes.positionAndSize(index * size, size);
  return t;
}
origin: OpenHFT/Java-Lang

public void positionAndSize(long offset, long size) {
  if (offset < 0 || size < 0 || offset + size > store.size())
    throw new IllegalArgumentException();
  setStartPositionAddress(store.address() + offset);
  capacityAddr = limitAddr = startAddr + size;
}
origin: OpenHFT/Java-Lang

  @Override
  public ByteBuffer sliceAsByteBuffer(ByteBuffer toReuse) {
    return sliceAsByteBuffer(toReuse, store);
  }
}
origin: OpenHFT/Java-Lang

  @Override
  public void recycle(T t) {
    if (freeList.size() < MAX_SIZE) {
      assert ((DirectBytes) ((Byteable) t).bytes()).store() == store;
      assert !freeList.contains(t) : "recycling object already recycled";
      freeList.add(t);
    }
  }
}
origin: OpenHFT/Java-Lang

@NotNull
public final DirectBytes bytes(long offset, long length) {
  return new DirectBytes(this, refCount, offset, length);
}
origin: OpenHFT/Java-Lang

@Override
public void get(long index, T element) {
  if (tClass.isInstance(element)) {
    DirectBytes bytes = (DirectBytes) ((Byteable) element).bytes();
    bytes.positionAndSize(index * size, size);
    return;
  }
  T t = acquire();
  DirectBytes bytes = (DirectBytes) ((Byteable) t).bytes();
  bytes.positionAndSize(index * size, size);
  ((Copyable) element).copyFrom(t);
  recycle(t);
}
origin: OpenHFT/Java-Lang

static void writeUTF1(DirectBytes bytes, @NotNull char[] chars, int strlen) {
  int i;
  ascii:
  {
    for (i = 0; i < strlen; i++) {
      char c = chars[i];
      if (c > 0x007F)
        break ascii;
      NativeBytes.UNSAFE.putByte(bytes.positionAddr + i, (byte) c);
    }
    bytes.skip(i);
    return;
  }
  bytes.skip(i);
  if (i < strlen)
    writeUTF2(bytes, chars, strlen, i);
}
origin: net.openhft/lang

@NotNull
public final  DirectBytes bytes(long offset, long length) {
  return new DirectBytes(this, refCount, offset, length);
}
origin: net.openhft/lang

@Override
public void get(long index, T element) {
  if (tClass.isInstance(element)) {
    DirectBytes bytes = (DirectBytes) ((Byteable) element).bytes();
    bytes.positionAndSize(index * size, size);
    return;
  }
  T t = acquire();
  DirectBytes bytes = (DirectBytes) ((Byteable) t).bytes();
  bytes.positionAndSize(index * size, size);
  ((Copyable) element).copyFrom(t);
  recycle(t);
}
origin: OpenHFT/Java-Lang

  static void writeUTF1(DirectBytes bytes, @NotNull CharSequence str, int strlen) {
    int i = 0;
    ascii:
    {
      for (; i < strlen - 3; i += 4) {
        char c0 = str.charAt(i);
        char c1 = str.charAt(i + 1);
        char c2 = str.charAt(i + 2);
        char c3 = str.charAt(i + 3);
        if ((c0 | c1 | c2 | c3) > 0x007F)
          break ascii;
        NativeBytes.UNSAFE.putInt(bytes.positionAddr + i, c0 | (c1 << 8) | (c2 << 16) | (c3 << 24));
      }
      for (; i < strlen; i++) {
        char c = str.charAt(i);
        if (c > 0x007F)
//            if (c + Integer.MIN_VALUE - 1 <= Integer.MIN_VALUE + 0x007F-1)
          break ascii;
        NativeBytes.UNSAFE.putByte(bytes.positionAddr + i, (byte) c);
      }
    }
    bytes.skip(i);
    if (i < strlen)
      writeUTF2(bytes, str, strlen, i);
  }

origin: OpenHFT/Java-Lang

@NotNull
public DirectBytes bytes(long offset, long length) {
  return new DirectBytes(this, refCount, offset, length);
}
origin: net.openhft/lang

  static void writeUTF1(DirectBytes bytes, @NotNull CharSequence str, int strlen) {
    int i = 0;
    ascii:
    {
      for (; i < strlen - 3; i += 4) {
        char c0 = str.charAt(i);
        char c1 = str.charAt(i + 1);
        char c2 = str.charAt(i + 2);
        char c3 = str.charAt(i + 3);
        if ((c0 | c1 | c2 | c3) > 0x007F)
          break ascii;
        NativeBytes.UNSAFE.putInt(bytes.positionAddr + i, c0 | (c1 << 8) | (c2 << 16) | (c3 << 24));
      }
      for (; i < strlen; i++) {
        char c = str.charAt(i);
        if (c > 0x007F)
//            if (c + Integer.MIN_VALUE - 1 <= Integer.MIN_VALUE + 0x007F-1)
          break ascii;
        NativeBytes.UNSAFE.putByte(bytes.positionAddr + i, (byte) c);
      }
    }
    bytes.skip(i);
    if (i < strlen)
      writeUTF2(bytes, str, strlen, i);
  }

net.openhft.lang.ioDirectBytes

Most used methods

  • <init>
  • positionAndSize
  • busyLock
  • readLong
  • setStartPositionAddress
  • skip
  • sliceAsByteBuffer
  • store
  • unlock

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getResourceAsStream (ClassLoader)
  • getContentResolver (Context)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • IOException (java.io)
    Signals a general, I/O-related error. Error details may be specified when calling the constructor, a
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • NumberFormat (java.text)
    The abstract base class for all number formats. This class provides the interface for formatting and
  • JOptionPane (javax.swing)
  • BasicDataSource (org.apache.commons.dbcp)
    Basic implementation of javax.sql.DataSource that is configured via JavaBeans properties. This is no
  • Join (org.hibernate.mapping)
  • 14 Best Plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now