pointer equivalence
Ty Young
youngty1997 at gmail.com
Tue Oct 20 18:44:49 UTC 2020
Hi,
Is there any plans to make pointer equivalence(==) work for objects that
are derived from native memory, so that:
MemorySegment segment =
MemorySegment.allocateNative(MemoryLayouts.JAVA_LONG);
VarHandle handle = MemoryHandles.varHandle(long.class,
ByteOrder.nativeOrder());
handle.set(segment, 0, 500);
Long valuePointer = (Long)handle.get(segment, 0);
Long valuePointer2 = (Long)handle.get(segment, 0);
System.out.println(valuePointer == valuePointer2);
prints true.
I'm guessing as-is if valuePointer was to go out-of-scope while being
part of a WeakHashMap, the WeakHashMap key would be removed. It seems
like everything stored in-memory is just a value as far as Java is
concerned, and the number classes, along with MemoryAddress, just create
new instances or point to cached ones.
I'm more interested in pointer equivalence when it comes to
MemoryAddress than numbers as it could be useful in creating
automatically managed native memory heaps. This, along with the fact
that MemorySegment.address() returns a new MemoryAddress instance(is
this a bug?) kinda throw a wrench into some ideas on how to make one.
More information about the panama-dev
mailing list