MCPcopy Create free account
hub / github.com/java-native-access/jna / getNativeSize

Method getNativeSize

src/com/sun/jna/Native.java:1459–1481  ·  view source on GitHub ↗

@param type The Java class for which the native size is to be determined @param value an instance of said class (if available) @return the native size of the given class, in bytes. For use with arrays.

(Class<?> type, Object value)

Source from the content-addressed store, hash-verified

1457 * For use with arrays.
1458 */
1459 public static int getNativeSize(Class<?> type, Object value) {
1460 if (type.isArray()) {
1461 int len = Array.getLength(value);
1462 if (len > 0) {
1463 Object o = Array.get(value, 0);
1464 return len * getNativeSize(type.getComponentType(), o);
1465 }
1466 // Don't process zero-length arrays
1467 throw new IllegalArgumentException("Arrays of length zero not allowed: " + type);
1468 }
1469 if (Structure.class.isAssignableFrom(type)
1470 && !Structure.ByReference.class.isAssignableFrom(type)) {
1471 return Structure.size((Class<Structure>) type, (Structure)value);
1472 }
1473 try {
1474 return getNativeSize(type);
1475 }
1476 catch(IllegalArgumentException e) {
1477 throw new IllegalArgumentException("The type \"" + type.getName()
1478 + "\" is not supported: "
1479 + e.getMessage());
1480 }
1481 }
1482
1483 /**
1484 * Returns the native size for a given Java class. Structures are

Callers 15

testInitializeAclMethod · 0.95
testGetAceMethod · 0.95
testAddAceMethod · 0.95
testCFArrayMethod · 0.95
testProcessStructuresMethod · 0.95
sizeOfMethod · 0.95
sizeOfMethod · 0.95
sizeOfMethod · 0.95
sizeOfMethod · 0.95

Calls 8

sizeMethod · 0.95
getInstanceMethod · 0.95
isBufferMethod · 0.95
isArrayMethod · 0.80
getNameMethod · 0.65
nativeTypeMethod · 0.65
getLengthMethod · 0.45
getMethod · 0.45

Tested by 8

testInitializeAclMethod · 0.76
testGetAceMethod · 0.76
testAddAceMethod · 0.76
testCFArrayMethod · 0.76
testProcessStructuresMethod · 0.76