freenode/#lisp - IRC Chatlog
Search
12:15:00
jackdaniel
if you are curious about ECL's FFI implementation, then you can read about it here: https://common-lisp.net/project/ecl/static/ecldoc/Extensions.html#Foreign-Function-Interface
12:15:46
jackdaniel
generally it follows UFFI API, which reference manual is included here: https://common-lisp.net/project/ecl/static/manual/pt04.html
12:17:58
black_13
if had a function "void foo(void);" defined in a .dll and had normal exports and this was built using visual studio how would i call
12:19:21
jackdaniel
first you load the library (see cffi's doc) then you call defcfun (see cffi doc)
12:19:48
jackdaniel
(defcfun "foo" :void) ; should create function foo which could be called like CL-REPL> (foo)
12:28:30
jackdaniel
while I understand that reading documentation may be a demanding task for various reason, that's why documentation is written - so a person who wrote it doesn't have to explain things over and over again
12:52:24
dlowe
people come to help on IRC because a) they want to know something they can't find in the manual, b) they don't want to read the manual, c) they need emotional support while trying to use your thing
12:58:53
TMA
If insults are to be meted out, it shall be done with dignity, style and proper grammar.
18:28:20
beginner_supreme
Hey all, curious if high-performance compilers create contiguous objects when given element-type, so for (make-array n :element-type some-object/struct), the rough equivalent in C would be: malloc(n * sizeof(some-object/struct));
18:29:47
beginner_supreme
Is this sort of contiguous allocation done at all for these types of expressions (not just for arrays) or are only pointers contiguous, having an extra indirection
18:37:20
copec
I'm not sure if all compilers do, but the presumption is that you are giving it sufficient information so that it can.
18:40:37
beginner_supreme
I read one opinion of it on stack overflow, and the idea is that it would stress the garbage collector out if such an optimization were done. https://stackoverflow.com/questions/29008545/any-ways-to-allocate-flattened-array-of-structure-as-c-in-common-lisp
18:42:12
stylewarning
beginner_supreme: in Common Lisp, usually will not be allocated necessarily like that
18:42:19
copec
If you have reached a point that that is important enough, I would consult the specific implementation docs and/or source
18:42:44
stylewarning
beginner_supreme: it'll be more like: void **array = malloc(n * sizeof (void *))
18:43:01
stylewarning
beginner_supreme: followed by n allocations of the objects, which will inadvertently be contiguous
18:46:55
beginner_supreme
For the future, are such inquiries suitable for this channel or must I refer them to #clnoobs?
18:50:11
copec
I tend to ask in clnoobs first, and reflect the question in here or one of the other CL channels if I can't get an answer. There are some pretty knowledgable people in there though, it's not newb on newb action
19:20:16
White_Flame
beginner_supreme: garbage collectors can clump together data references by their nature. you can stack-allocate in CL (dynamic-extent). and of course, type-specified vectors as you mentioned
19:22:08
beginner_supreme
So the allocated objects themselves would be contiguous, but would the vector would still contain pointers to those objects, not the objects themselves. Right?
19:23:11
White_Flame
vectors of numbers, characters, etc, can often be packed together. Vectors of structs and such might not
19:24:19
White_Flame
of course, you need to specialize its type as you create it to try to gain such advantages
19:25:00
dlowe
even if you have a vector of structs, they're not going to be laid out in memory like they would in C
19:26:34
White_Flame
you might get the struct slots themselves, but structs themselves don't use special packed representations. If the slot value fits in a machine word, it'll be in the struct. Else it'll be a pointer
19:26:54
White_Flame
erm, you might get a typed vector to hold a linear array of the struct slots themselves...
19:27:08
makomo
dlowe: is that guaranteed or just something that's not really done by compilers or something else?
19:27:50
makomo
so hypothetically, you *could* have a vector in which the structs are laid out contigiously without any indirection
19:28:32
White_Flame
but since dereferencing is though standard functions, as the number of types of backends to those functions increases, so does the amount of type testing & dispatch
19:29:39
White_Flame
CLOS objects can be defined to migrate to new versions of their class. instantiated structs keep their old structure around if you re-defstruct
19:29:54
stylewarning
the real problem imo is the meaning of (setf (aref packed-array i) new-struct)
19:30:17
stylewarning
how referencing/pointers/etc work. You would need typed pointers into typed arrays
19:31:57
stylewarning
it would be so cool if (UPGRADED-ARRAY-ELEMENT-TYPE S) == S for a structure type S
19:33:03
stylewarning
I'd even be happy with a super special struct type, like array of packed words or something
19:34:13
White_Flame
yeah, an extended cons cell with >2 slots is something I've mused about on occasion
19:34:19
aeth
arrays of structs, typed lists (this is trivial to do yourself from structs, but it won't be as efficient), and typed hash tables are on my wish list, as well as type declarations behaving everywhere like in SBCL (permits gradual typing) and being able to declare specific optimizations (like TCO or fast floating point) rather than general categories
19:34:39
aeth
Add all of the stuff on the list I just gave and CL is a good competitor for something like C# or Java
19:35:53
Bike
if it's a structure of uniformly typed slots you could probably fake it with some special functions or macros
19:36:54
aeth
e.g. no need to put a struct of (x, y, z) single-floats in an array when I can just have a 2D array
19:37:43
aeth
I then cover this up with my array macros, which are fairly elaborate. https://gitlab.com/zombie-raptor/zombie-raptor/blob/18db1a4e34892adf4f2f4c20d52df416a3a340a9/util/array.lisp
19:38:56
aeth
e.g. (setf (array-row-of-4 foo 32) (array-of-4 some-array)) ; essentially copies the first four elements of an array (no checking, so it's faster) into the first four elements of the array row 32
19:40:06
aeth
Unfortunately, this isn't a perfect substitute for arrays-of-structs because all items have to be of the same type (which could be T, I guess)
19:41:03
aeth
(It's not really copying, either, but if you're doing specialized arrays (numbers or characters) you don't really notice.)
19:41:39
stylewarning
aeth: I've faked it by defining things like (define-struct-array <defstruct options>) which just creates a struct-of-arrays
19:42:18
stylewarning
aeth: It at least makes things a bit more efficient, even if you're not reaping all of the rewards of having a single object or having a lot of memory locality.
19:47:08
beginner_supreme
The point made about how avoiding indirection by not having an vector of pointers would require typed pointers for pointer arithmetic is a nice point..
19:58:37
aeth
copec: I tried 2-3 times to get it through roswell, which I use to test in various implementations, but after failing 2-3 times (and it's a long, C++ compile) I don't want to try again via roswell
20:44:00
antoszka
copec: https://common-lisp.net/ <- that might be another starting point, probably also worth idling less here and on #clnoobs and #lispgames
23:46:35
aeth
If you had a way to sort https://www.quicklisp.org/beta/releases.html by category you'd get basically the same result. A list of everything, but with no way of telling if it's actually up to date, worth using, etc.
23:54:13
aeth
Library selection is a tricky thing. There isn't really one Common Lisp. It's a very multi-paradigm language. Sure, you can definitely write code that's not "Lispy", but even if the code is "Lispy" there's many different valid styles.
23:57:34
aeth
Lisp is not even necessarily a dynamically typed language! SBCL did gradual typing years before it was cool.
0:05:38
black_13_
or what argument should be given to (ffi:load-foreign-library on a windows machine