News for hackers. Stuff that matters.
Re:Garnet – A new remote cache-store from Microsoft Research by larodi on Tuesday March 19, 2024 @02:49AM (#39753477)
Is it possible to have unmanaged code in Java at all… or you mean linking libs and exposing them through Java API in the lang?
Re:Garnet – A new remote cache-store from Microsoft Research by rfoo on Tuesday March 19, 2024 @03:29AM (#39753637)
Ah, I meant Java code manipulating off-heap memory. For Java I don't think there's a way to mix managed and unmanaged code like you do in C#/C++ CLR.
Re:Garnet – A new remote cache-store from Microsoft Research by neonsunset on Tuesday March 19, 2024 @03:36AM (#39753676)
In C# you usually don't want to mix in C++. Manipulating off-heap memory is indeed easy - nowadays pointers to both object interiors, stack and unmanaged memory can be represented as `ref T` where T is byte, int, etc.

These are then subsequently wrapped by `Span<T>` and `ReadOnlySpan<T>` respectively. This way a span can be a slice of memory that can have any origin:

    var fromStack1 = (stackalloc byte[32]);
    var fromStack2 = (Span<byte>)[0x20, 0x20, 0x20, 0x20];
    var fromHeap = new byte[32].AsSpan();
    unsafe
    {
        var ptr = NativeMemory.Alloc(32);
        var fromMalloc = new Span<byte>(ptr, 32);
        // Don't forget to free :)
    }
Re:Garnet – A new remote cache-store from Microsoft Research by pjmlp on Tuesday March 19, 2024 @05:20AM (#39754051)
Panama has helped into that direction, it isn't like C# though, for feature parity we will eventually need Valhalla, which since they want to keep existing JARs working, it is taking its time.

Ignoring the type systems from Eiffel, Objective-C, Oberon and Modula-3 linage, even though they were inspirations for Java, has been shown to have been a bad decision in hindsight.