Add support for layouts being passed to size-of and align-of
This commit is contained in:
parent
7350a5df1c
commit
b960c01bb3
1 changed files with 9 additions and 5 deletions
|
|
@ -378,18 +378,22 @@
|
||||||
|
|
||||||
If a type serializes to a primitive it returns return a Java primitive type.
|
If a type serializes to a primitive it returns return a Java primitive type.
|
||||||
Otherwise, it returns [[MemorySegment]]."
|
Otherwise, it returns [[MemorySegment]]."
|
||||||
[type]
|
^Class [type]
|
||||||
(java-prim-layout (or (primitive-type type) type) MemorySegment))
|
(java-prim-layout (or (primitive-type type) type) MemorySegment))
|
||||||
|
|
||||||
(defn size-of
|
(defn size-of
|
||||||
"The size in bytes of the given `type`."
|
"The size in bytes of the given `type`."
|
||||||
[type]
|
^long [type]
|
||||||
(.byteSize ^MemoryLayout (c-layout type)))
|
(let [t (cond-> type
|
||||||
|
(not (instance? MemoryLayout type)) c-layout)]
|
||||||
|
(.byteSize ^MemoryLayout t)))
|
||||||
|
|
||||||
(defn align-of
|
(defn align-of
|
||||||
"The alignment in bytes of the given `type`."
|
"The alignment in bytes of the given `type`."
|
||||||
[type]
|
^long [type]
|
||||||
(.byteAlignment ^MemoryLayout (c-layout type)))
|
(let [t (cond-> type
|
||||||
|
(not (instance? MemoryLayout type)) c-layout)]
|
||||||
|
(.byteAlignment ^MemoryLayout t)))
|
||||||
|
|
||||||
(defn alloc-instance
|
(defn alloc-instance
|
||||||
"Allocates a memory segment for the given `type`."
|
"Allocates a memory segment for the given `type`."
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue