

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
13 messages in net.java.dev.jna.users[jna-users] Some questions about com....| From | Sent On | Attachments |
|---|---|---|
| Albert Strasheim | Jan 6, 2009 11:33 am | |
| Timothy Wall | Jan 6, 2009 11:58 am | |
| Albert Strasheim | Jan 6, 2009 12:08 pm | |
| Timothy Wall | Jan 6, 2009 12:12 pm | |
| Timothy Wall | Jan 6, 2009 12:14 pm | |
| Albert Strasheim | Jan 6, 2009 12:21 pm | |
| Timothy Wall | Jan 6, 2009 12:29 pm | |
| Albert Strasheim | Jan 6, 2009 12:37 pm | |
| Daniel Kaufmann | Jan 6, 2009 4:26 pm | |
| Albert Strasheim | Jan 6, 2009 6:38 pm | .diff |
| Albert Strasheim | Jan 8, 2009 7:30 pm | |
| Paul Loy | Jan 9, 2009 1:40 am | |
| Timothy Wall | Jan 9, 2009 4:45 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | [jna-users] Some questions about com.sun.jna.Memory | Actions... |
|---|---|---|
| From: | Albert Strasheim (full...@gmail.com) | |
| Date: | Jan 6, 2009 11:33:55 am | |
| List: | net.java.dev.jna.users | |
Hello all
I have a few questions about com.sun.jna.Memory.
I previously used JNA for calling some native functions with a Java matrix library that stored its data using native NIO buffers.
This worked great, but you run into limitations in the NIO API when you go to buffers larger than 2 GB. NIO2 might fix this, but I need a solution in the mean time.
Using com.sun.jna.Memory instead of a NIO buffer seems like it could work. However, I have a few comments about this class.
It seems like it would be more useful if Memory's align and share methods returned Memory instead of Pointer. This change would allow one to call getSize() on the SharedMemory returned when using these methods to check on the size of the new buffer.
I also noticed that calling align() on a small buffer with a large byte boundary causes problems:
Memory buf = new Memory(10); System.out.println(buf.align(16384));
prints
allocated@0x4c570000 (-2742 bytes) (shared from allocated@0x4c56f540 (10 bytes))
Also, this code fails:
Memory buf = new Memory(0);
but the error message isn't quite right:
java.lang.IllegalArgumentException: Allocation size must be >= 0
I would actually think that allowing an allocation size of 0 could be useful to negate the need for other code to deal with this corner case.
I also think it could be useful if one could explicitly call free() on a Memory instance instead of relying on the finalizer. This becomes useful when one is dealing with many large buffers that use up most of the available memory.
To make things more robust in this case, SharedMemory could be changed to check whether its underlying Memory instance has been freed and if so, throw a runtime error of some sort.
I could build these ideas into my own "Memory2" class, but I thought it might be useful to think about incorporating them into JNA's Memory for others to use.
Thanks for your time.
Regards,
Albert








.diff