objsize.ml 474 B

12345678910111213141516171819
  1. if Sys.ocaml_version < "3.11"
  2. then
  3. failwith "Objsize >=0.12 can only be used with OCaml >=3.11"
  4. type info =
  5. { data : int
  6. ; headers : int
  7. ; depth : int
  8. ; reached : bool
  9. }
  10. external internal_objsize : Obj.t -> Obj.t list -> Obj.t list -> info = "ml_objsize"
  11. let objsize obj exclude reach = internal_objsize (Obj.repr obj) exclude reach
  12. let size_with_headers i = (Sys.word_size/8) * (i.data + i.headers)
  13. let size_without_headers i = (Sys.word_size/8) * i.data