11package cn .apisium .shm ;
22
33import cn .apisium .shm .impl .WindowsSharedMemory ;
4+ import org .jetbrains .annotations .Contract ;
5+ import org .jetbrains .annotations .NotNull ;
46
7+ import java .lang .foreign .MemorySegment ;
58import java .nio .ByteBuffer ;
69
710/**
@@ -13,18 +16,31 @@ public interface SharedMemory extends AutoCloseable {
1316 * Get the shared memory as a {@link ByteBuffer}.
1417 * @return The shared memory as a {@link ByteBuffer}.
1518 */
19+ @ NotNull
20+ @ Contract (pure = true )
1621 ByteBuffer toByteBuffer ();
1722
23+ /**
24+ * Get the shared memory as a {@link MemorySegment}.
25+ * @return The shared memory as a {@link MemorySegment}.
26+ */
27+ @ NotNull
28+ @ Contract (pure = true )
29+ MemorySegment getMemorySegment ();
30+
1831 /**
1932 * Get the size of the shared memory.
2033 * @return The size of the shared memory.
2134 */
35+ @ Contract (pure = true )
2236 int size ();
2337
2438 /**
2539 * Get the name of the shared memory.
2640 * @return The name of the shared memory.
2741 */
42+ @ NotNull
43+ @ Contract (pure = true )
2844 String getName ();
2945
3046 /**
@@ -33,7 +49,8 @@ public interface SharedMemory extends AutoCloseable {
3349 * @param size The size of the shared memory.
3450 * @return The shared memory.
3551 */
36- static SharedMemory open (String name , int size ) {
52+ @ NotNull
53+ static SharedMemory open (@ NotNull String name , int size ) {
3754 return init (name , size , false );
3855 }
3956
@@ -43,19 +60,22 @@ static SharedMemory open(String name, int size) {
4360 * @param size The size of the shared memory.
4461 * @return The shared memory.
4562 */
46- static SharedMemory create (String name , int size ) {
63+ @ NotNull
64+ static SharedMemory create (@ NotNull String name , int size ) {
4765 return init (name , size , true );
4866 }
4967
5068 /**
5169 * Check if the current system is supported.
5270 * @return If the current system is supported.
5371 */
72+ @ Contract (pure = true )
5473 static boolean isSupported () {
5574 return CABI .SYSTEM_TYPE == CABI .SystemType .Windows ;
5675 }
5776
58- private static SharedMemory init (String name , int size , boolean isCreate ) {
77+ @ NotNull
78+ private static SharedMemory init (@ NotNull String name , int size , boolean isCreate ) {
5979 try {
6080 return switch (CABI .SYSTEM_TYPE ) {
6181 case Windows -> new WindowsSharedMemory (name , size , isCreate );
0 commit comments