Memory Allocation

21 views
Skip to first unread message

Tim Roberts

unread,
Apr 3, 2016, 10:28:15 PM4/3/16
to Extempore
Hi All,
I'm having issues with allocating memory.  I'm doing Ben's tutorial and getting my head around allocation in Extempore vs C.
I've run into an issue, where I try to evaluate this code:

(bind-func fill_buffer_closure_zone2 10000 ;; zone size: 10KB
  (let ((region_length 1000)
        (int_buf:i64* (zalloc region_length))
        (i:i64 0))
    (lambda ()
      (dotimes (i region_length)
        (pset! int_buf i i))
      (printf "int_buf[366] = %lld\n"
              (pref int_buf 366)))))

Copied directly from http://benswift.me/2012/08/17/memory-management-in-extempore/ and get this error back.

Type Error bad numeric value 1000, should be double 


In writing this, I tried explicitly defining region_length, and it works when defined as an i64.  Interestingly, the closure signature is returned as [i32]*.  Is that because of the printf statement?

Toby Gifford

unread,
Apr 3, 2016, 11:24:21 PM4/3/16
to extemp...@googlegroups.com
Hi Tim,

Yes you should explicitly type region_length as an i64 (though i'm surprised the type inferencer doesn't work in this case).

And yes, the last expression is a printf function which returns an i32, hence the closure signature.

--
You received this message because you are subscribed to the Google Groups "Extempore" group.
To unsubscribe from this group and stop receiving emails from it, send an email to extemporelan...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages