ITeye博客

chl0000的博客

chl0000 · 共 2 篇文章

python LInux下使用ctypes操作内存

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创建一个ctypes对象 ctypes_raw_type = (ctyp…

2013-07-30 02:06 · python · 评论(0)

Linux下使用python读取共享内存

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_buf(char *buf) { int i=0; while((buf[i]=getchar())!='\n'&&…

2013-07-30 01:43 · python · 评论(0)