Writes the fields of the struct to native memory
()
| 781 | * Writes the fields of the struct to native memory |
| 782 | */ |
| 783 | public void write() { |
| 784 | // Avoid writing to a null pointer |
| 785 | if (memory == PLACEHOLDER_MEMORY) { |
| 786 | return; |
| 787 | } |
| 788 | |
| 789 | // convenience: allocate memory if it hasn't been already; this |
| 790 | // allows structures to do field-based initialization of arrays and not |
| 791 | // have to explicitly call allocateMemory in a ctor |
| 792 | ensureAllocated(); |
| 793 | |
| 794 | // Update native FFI type information, if needed |
| 795 | if (this instanceof ByValue) { |
| 796 | getTypeInfo(); |
| 797 | } |
| 798 | |
| 799 | // Avoid redundant writes |
| 800 | if (!busy().add(this)) { |
| 801 | return; |
| 802 | } |
| 803 | try { |
| 804 | // Write all fields, except those marked 'volatile' |
| 805 | for (StructField sf : fields().values()) { |
| 806 | if (!sf.isVolatile) { |
| 807 | writeField(sf); |
| 808 | } |
| 809 | } |
| 810 | } |
| 811 | finally { |
| 812 | busy().remove(this); |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | /** Write the given field to native memory. The current value in the Java |
| 817 | * field will be translated into native memory. |