Skip to content

Instantly share code, notes, and snippets.

@helinwang
helinwang / gostring.md
Last active January 3, 2023 07:50
Call go (or c) code from python with string as argument and string as return value

go code (foo.go) compiled into a shared library and a c header (foo.h) is generated.

For calling go from c, please see here

Arguments

The code below shows two ways of passing string parameter to go function:

  1. Using GoString structure as argument, without making a copy in go code: no conversion to go string needed.
  2. Using c_char_p as argument, making a copy in go code when converting to go string.

When using the first method without the copy, I don't know how python will do the memory management with the pointer passed into go. So the second method is preferred.

@NF1198
NF1198 / README.md
Last active August 27, 2023 11:11
Simultaneously read from multiple subprocesses in Python 3 using {select, threads} (select, epoll, thread, subprocess, PIPE)

Reading from multiple subprocesses in Python: epoll vs threads

The following performance results were generated using a 2300 line file with output piped directly to a file instead of the console. (All awk delays were set to 0 for the benchmark) Processor Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz, 1992 Mhz, 4 Core(s), 8 Logical Processor(s)

The epoll solution is the clear winner, but is only available on Unix and Linux.

Approach 1: epoll

  • real 0m24.954s
@ctsrc
ctsrc / README.md
Last active February 1, 2024 09:14 — forked from niw/README.en.md
Guide: Run FreeBSD 13.1-RELEASE for ARM64 in QEMU on Apple Silicon Mac (MacBook Pro M1, etc) with HVF acceleration (Hypervisor.framework)
@tailriver
tailriver / dlopen_sample.c
Created November 18, 2015 04:21
A sample of using dlopen library.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
int main(int argc, char** argv)
{
void *handle;
void (*func_print_name)(const char*);