Lisp HUG Maillist Archive

FLI question (alloc-foreign-object)

If I pass :initial-contents, but don't pass :nelems, everything *appears* to work, but I don't know if I'm really just overwriting memory and delaying an inevitable crash.

Example:

(with-dynamic-foreign-objects ((v :int :initial-contents '(1 2 3 4)))
  (dereference v :index 2))

;=> 3

Does alloc-foreign-object understand that a sequence was passed to :initial-contents and allocate enough space for all the contents? Or am I expected to calculate the length myself and always pass :nelems when I need to allocate more than one element?

Jeff M.

Re: FLI question (alloc-foreign-object)

try macro expanding it, you should see that it calculates the length of the initial-contents

HiH

Ala'a


On Sun, Sep 22, 2013 at 7:52 PM, Jeffrey Massung <massung@gmail.com> wrote:
If I pass :initial-contents, but don't pass :nelems, everything *appears* to work, but I don't know if I'm really just overwriting memory and delaying an inevitable crash.

Example:

(with-dynamic-foreign-objects ((v :int :initial-contents '(1 2 3 4)))
  (dereference v :index 2))

;=> 3

Does alloc-foreign-object understand that a sequence was passed to :initial-contents and allocate enough space for all the contents? Or am I expected to calculate the length myself and always pass :nelems when I need to allocate more than one element?

Jeff M.

Re: FLI question (alloc-foreign-object)

Unable to parse email body. Email id is 12487

Updated at: 2020-12-10 08:35 UTC