4 min read
#Affix.pm
Sometimes, the best tool for the job involves three different tools. You might have legacy math models in Fortran, performance-critical loops in Assem...
6 min read
#Affix.pm
C might be the lingua franca of system programming, but Affix::Build is a true polyglot. We've covered building shared libraries in C and C++ but Affi...
4 min read
#Affix.pm
4 min read
#Affix.pm
Is Affix faster than... everything else?...
3 min read
#Affix.pm
In C, OOP is often simulated using structs containing function pointers. This pattern is commonly known as a vtable and allows a library to call diffe...
1 min read
#Affix.pm
Manual free() is error-prone. We can use Perl's DESTROY phase to automate it....
4 min read
#Affix.pm
When things go wrong in Perl, you probably get an error message. When they go wrong in C, you get a segfault, a frozen terminal, or data corruption th...
1 min read
#Affix.pm
System calls fail. In C, you check the global errno variable (or GetLastError() on Windows). In Affix, we expose this via errno()....
6 min read
#Affix.pm
Bridging I/O between languages is historically one of the most fragile aspects of FFI. While handling file descriptors manually as opaque pointers may...
3 min read
#Affix.pm
Speed is the reason I wrote infix and Affix and I think I've achieved a good balance of features vs. speed. I've done a lot of work to reduce overhead...
4 min read
#Affix.pm
C headers are full of enum definitions. To the C compiler, these are just integers. To the programmer, they have semantic meaning. When binding these...
2 min read
#Affix.pm
In a previous chapter, we passed a simple callback. But real-world C libraries often take a callback and an opaque pointer (usually something like voi...
3 min read
#Affix.pm
Sometimes you need to peek inside the oven. If a function expects a C style struct to be passed by value or if you want to read struct members without...
4 min read
#Affix.pm
C libraries often use callback functions to delegate logic back to the user. The standard library's qsort is the classic example: it knows how to sort...
4 min read
#Affix.pm
Some C functions don't have a fixed number of arguments. The most famous example is printf, which takes a format string and... almost everything else....
3 min read
#Affix.pm
In C, arrays passed to functions are often used as output buffers. The function reads data from the array, modifies it in place, and expects the calle...
3 min read
#Affix.pm
In C, arrays and pointers are cousins. In function arguments, they are twins. Declaring void func(int a[]) is exactly the same as void func(int *a). H...
4 min read
#Affix.pm
Perl scripts often live in the terminal or deep inside a server handing out webpages or whatnot, but they don't have to stay there. Earlier, in chapte...
3 min read
#Affix.pm
Perl handles memory for you. C does not. When you start allocating raw memory buffers in Affix, you are stepping into the C world. This recipe demonst...
4 min read
#Affix.pm
Affix cannot directly instantiate a C++ class or read a C struct unless we define every single field with the correct type and in the proper order. Of...
2 min read
#Affix.pm
Every operating system comes with a "C standard library" or, simply, libc. It contains the fundamental building blocks of C programming: memory alloca...
4 min read
#Affix.pm
Dealing with C strings usually involves asking "Who owns this memory?"...
3 min read
#Affix.pm
C strings are simple: they start at a memory address and end at the first zero/null byte (\0). But what if your data contains nulls? If you use standa...
3 min read
#Affix.pm
When interacting with the Windows API (Win32), you will inevitably face two facts: libraries are named things like user32.dll, and text is almost alwa...
4 min read
#Affix.pm
Sometimes, you don't have a pre-existing .dll or .so file. Sometimes, you just have an idea, a heavy mathematical loop, or a snippet of C code you fou...
7 min read
#Affix.pm
Welcome to the Affix Cookbook! This guide is a living collection of recipes, techniques, and architectural patterns for mastering Foreign Function Int...
5 min read
#infix
We have nearly reached the end of the current roadmap. infix is fast, secure, and portable. But optimization is an addiction, and I am already looking...
5 min read
#infix
This is an explanation and expansion of discussion #26 now that I've started actually implemented and designed my idea....
7 min read
#infix
I've had this idea for a while now and might put effort into it next. I understand that this would be a massive task but the first 30% of it is alread...
2 min read
#infix
Shower thought time... Internally, would it be faster to coerce args that would end up on the stack into a single block of malloc'd memory? Currently,...