+ ((Buffer)buf).flip();
+ // This code is quite hot during initial network graph sync, so we go a ways out of
+ // our way to avoid object allocations that'll make the GC sweat later -
+ // * when we're hot, we'll likely often be reading the full buffer, so we keep
+ // around a full-buffer-sized byte array to reuse across reads,
+ // * We use the manual memory management call logic directly in bindings instead of
+ // the nice "human-readable" wrappers. This puts us at risk of memory issues,
+ // so we indirectly ensure compile fails if the types change by writing the
+ // "human-readable" form of the same code in the dummy function below.
+ byte[] read_bytes;
+ if (read == BUF_SZ) {
+ read_bytes = max_buf_byte_object;
+ } else {
+ read_bytes = new byte[read];
+ }