Module Ctypes.CArray
Operations on C arrays.
type 'a t= 'a carray
val get : 'a t -> int -> 'aget a nreturns thenth element of the zero-indexed arraya. The semantics for non-scalar types are non-copying, as for(!@).If you rebind the
CArraymodule toArraythen you can also use the syntaxa.(n)instead ofArray.get a n.Raise
Invalid_argument "index out of bounds"ifnis outside of the range0to(CArray.length a - 1).
val set : 'a t -> int -> 'a -> unitset a n voverwrites thenth element of the zero-indexed arrayawithv.If you rebind the
CArraymodule toArraythen you can also use thea.(n) <- vsyntax instead ofArray.set a n v.Raise
Invalid_argument "index out of bounds"ifnis outside of the range0to(CArray.length a - 1).
val unsafe_get : 'a t -> int -> 'aunsafe_get a nbehaves likeget a nexcept that the check thatnbetween0and(CArray.length a - 1)is not performed.
val unsafe_set : 'a t -> int -> 'a -> unitunsafe_set a n vbehaves likeset a n vexcept that the check thatnbetween0and(CArray.length a - 1)is not performed.
val of_string : string -> char tof_string sbuilds an array of the same length ass, and writes the elements ofsto the corresponding elements of the array.
val of_list : 'a typ -> 'a list -> 'a tof_list t lbuilds an array of typetof the same length asl, and writes the elements oflto the corresponding elements of the array.
val to_list : 'a t -> 'a listto_list abuilds a list of the same length asasuch that each element of the list is the result of reading the corresponding element ofa.
val iter : ('a -> unit) -> 'a t -> unititer f ais analogous toArray.iter f a: it appliesfin turn to all the elements ofa.
val map : 'b typ -> ('a -> 'b) -> 'a t -> 'b tmap t f ais analogous toArray.map f a: it creates a new array with element typetwhose elements are obtained by applyingfto the elements ofa.
val mapi : 'b typ -> (int -> 'a -> 'b) -> 'a t -> 'b tmapibehaves likeArray.mapi, except that it also passes the index of each element as the first argument tofand the element itself as the second argument.
val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'aCArray.fold_left (@) x acomputes(((x @ a.(0)) @ a.(1)) ...) @ a.(n-1)wherenis the length of the arraya.
val fold_right : ('b -> 'a -> 'a) -> 'b t -> 'a -> 'aCArray.fold_right f a xcomputesa.(0) @ (a.(1) @ ( ... (a.(n-1) @ x) ...))wherenis the length of the arraya.
val length : 'a t -> intReturn the number of elements of the given array.
val from_ptr : 'a ptr -> int -> 'a tfrom_ptr p ncreates ann-length array reference to the memory at addressp.
val make : ?finalise:('a t -> unit) -> 'a typ -> ?initial:'a -> int -> 'a tmake t ncreates ann-length array of typet. If the optional argument?initialis supplied, it indicates a value that should be used to initialise every element of the array. The argument?finalise, if present, will be called just before the memory is freed.