13 ms·
I like the irony, you can not say that C# is superior to Java in every way in a discussion about C# Span while Java as ByteBuffer (the same API) since Java 4 (c
by _old_dude_ 9y ago
I like the irony,
you can not say that C# is superior to Java in every way in a discussion about C# Span while Java as ByteBuffer (the same API) since Java 4 (circa 2002 i think).
- benaadams 9y agoSpan<T> out of the box you can use with any type, not just Byte, Char, Double, Float, Int, Long, Short It can be put over an array (as per ByteBuffer); but also over stack allocated memory; a native pointer T* etc The underlying allocation is separate from the type
- _old_dude_ 9y agoByteBuffer provides universal access to on heap/off heap data. JNI or Unsafe allow to create ByteBuffer from native pointers, created in C/C++ or in Java using malloc, memcopy them, etc. This is used (and abused) by most web servers, DataStax or LMAX-Exchange have even created their whole business on that. You also have have CharBuffer, DoubleBuffer, FloatBuffer, etc There is no stack allocated ByteBuffer in Java (Java provides no stack access, this is religious) but in Java can do relaxed data access on Buffer element, volatile access, opaque access, CAS, etc. This is the same API.
- benaadams 9y agoDoes it work over non-primitive and user defined types? Object, InetAddress, etc Though only `struct` value types should be used in stack or native memory due to risk of GC holes
- _old_dude_ 9y agoNo, not yet. I believe there is a prototype of that kind of buffers that comes with the valhalla project (value types) but i've not tested it.