objsize.ml 597 B

123456789101112131415161718192021
  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:Obj.t list) (reach:Obj.t list) =
  12. (* internal_objsize (Obj.repr obj) exclude reach *)
  13. {data = (Obj.reachable_words (Obj.repr obj)); headers = 0; depth = 0; reached = false}
  14. let size_with_headers i = (Sys.word_size/8) * (i.data + i.headers)
  15. let size_without_headers i = (Sys.word_size/8) * i.data