Java Unsafe.copyMemory java.lang.IllegalArgumentException

前端 未结 1 1882
情歌与酒
情歌与酒 2021-01-19 09:15

I have a problem with copyMemory from Unsafe. I spent 2 days in resolving it but with no result. The code presented below always ends up with \"IllegalArgumentException\".

相关标签:
1条回答
  • 2021-01-19 09:52

    This version of Unsafe.copyMemory unfortunately only works for copying to offheap memory areas (by providing null as destination + a absolute memory address instead of an offsett) or when copying to a primitive array.

    When trying to specify anything else but null or a primitve array as third argument you will get an java.lang.IllegalArgumentException.

    Alternatively you could use the Unsafe.copyMemory (long srcAddress, long destAddress, long bytes) and directly provide the addresses (which of course is risky as the objects might have moved in the meantime).

    0 讨论(0)
提交回复
热议问题