Is there a way to get object's size? I want to know, how much memory waste my doubles.
Name:
Anonymous2012-03-09 7:44
(defmacro sizeof (type)
(let* ((n 100000)
(o (with-output-to-string (s)
(let ((*standard-output* s)
(*trace-output* s))
(eval `(time (make-array ,n :element-type ',type))))))
(o (loop for i = 0 then (1+ j)
as j = (position #\Newline o :start i)
collect (subseq o i j)
while j))
(o (caddr (reverse o)))
(o (coerce (remove-if (lambda (x) (char= x #\,)) (coerce o 'list))
'string))
(o (truncate (read-from-string o) n)))
o))
Name:
Anonymous2012-03-09 8:43
>>2
Tried on several Lisps. Good CL implementations seems prefer simple C/C++ arrays internally, respecting the size requested with :element-type, rounded to power of 2. Fixnum varies in size between 32-bit and 64-bit systems. So (make-array 1234 :element-type '(unsigned-byte 16)) gives exactly the same amount of memory as uint16 a[1234]
And if one gets CFFI pointer to array's memory, he can call C/C++ code without any overhead or get a direct pointer to DMA buffer or register area.
Name:
Anonymous2012-03-09 12:31
Following paper by japanese author says that "Lisp is shit", then explains why.
cl-www.msi.co.jp/solutions/knowledge/lisp-world/tutorial/compiler-eval-e.pdf
ACL does not perform this constant folding. The policy of arithmetics of fixnum-type declared values of SBCL and LispWorks is different from that of ACL. After all, however, they do not perform fold.
One might think that such optimization is not serious because skillful programmers can do this by coding time. But these redundant expressions often arise a result of various optimizations. Thus optimizing compilers often call constant folding after those optimizations. And the folding is important to improve the quality of the next code optimizations.
compiler performing good code optimizations has a good constant folder. in other words, poor constant folder reveals poor code optimizations.
Name:
Anonymous2012-03-09 12:37
constant propagation is not performed in ACL. SBCL fails to propagete the constants. LispWorks also fails.
Incorporating work of constant propagation and constant folding may drastically simplify macros. Thus not only for numerical computations, this optimization should be essential for extensive use of macros.