- 浏览: 13321 次
最新评论
文章列表
ctypes创建的内存不能自动对齐,可以使用如下方法对齐内存:
# _*_ coding:UTF-8
import sys
import time
import os
import ctypes
import ctypes.util
def ctypes_alloc_aligned(size, alignment):
buf_size = size + (alignment - 1)
#先使用bytearray函数分配一块内存
raw_memory = bytearray(buf_size)
#然后从raw_memory创建一个 ...
python没有独立的库可以读取linux下的共享内存,下面使用ctypes调用系统的API读取共享内存的内容
使用C++创建共享内存
#include <stdio.h>
#include <iostream>
#include <unistd.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdlib.h>
#include <errno.h>
#define MY_SHM_ID 67483
void get_ ...