From: Vsevolod D. <vse...@gm...> - 2016-12-07 14:10:49
|
Hi, I was looking in the mailing list archives and over the Internet but couldn't find a reference to any code that allows calculating the byte size of a particular object (mainly, a structure, array or list) in SBCL memory. I think, no one will argue that this is a handy tool for the selection of a particular data structure and its layout when dealing with big in-memory data sets - its primary purpose would be validating a particular choice with the real-world numbers. Another use case might be memory profiling: finding the largest object on the heap currently. I've also taken a look into room.lisp, but the code found there doesn't provide enough substance to easily build such a tool. I saw how sb-vm::map-allocated-objects could be used as it calculates the bytes used by the object "meta information", but it doesn't account for object's contents, i.e. it works similar to sizeof(type) invocation in C. And what about sizeof(instance) - how can it be implemented in SBCL? Also, another interesting feature of vm::map-allocated-objects is that for some objects it doesn't have access to them immediately, but "gains" it after several seconds: CL-USER> (defparameter *v* #(1 2 3)) *V* CL-USER> (sizeof *v*) NIL ;; after a couple of seconds CL-USER> (sizeof *v*) 48 where (defun sizeof (o) (sb-vm::map-allocated-objects (lambda (obj obj-tag n-obj-bytes) (when (eql obj o) (return-from sizeof n-obj-bytes))) :dynamic)) I'd be grateful for any hints on this matter Vsevolod --- Vsevolod Dyomkin +38-096-111-41-56 skype, twitter: vseloved |