Ability to extend a MemorySegment

Ty Young youngty1997 at gmail.com
Tue Jan 21 17:03:15 UTC 2020


Yes.


Union<Long> union = Union.ofLayouts(MemoryLayouts.JAVA_BYTE, 
MemoryLayouts.JAVA_LONG, MemoryLayouts.JAVA_INT);

Field<Long> field = union.getField(1);

field.setValue(Long.MAX_VALUE);

System.out.println(field.getValue()); // GOOD

union.setValue(Long.MIN_VALUE);

System.out.println(field.getValue()); // BAD

field.setValue(Long.MAX_VALUE);

System.out.println(union.getValue()); // BAD

System.out.println(field.getValue()); // GOOD


Union class can be found here: 
https://github.com/BlueGoliath/Crosspoint/blob/master/src/main/java/org/goliath/crosspoint/unions/BasicUnion.java



On 1/21/20 10:39 AM, Maurizio Cimadamore wrote:
> Not aware of anything deliberate here - do you have an example?
>
> Maurizio
>
> On 21/01/2020 16:31, Ty Young wrote:
>> I've noticed some weirdness with Unions in Memory Access as well - 
>> creating a slice that is the exact size of the Union's 
>> MemoryAddress(long for example) and applying a value results in the 
>> Union's base MemoryAddress being made invalid(despite being the same 
>> size). Maybe that's intentional. 


More information about the panama-dev mailing list