[备忘]通过LuaJIT的FFI使用mmap功能

 

 

ffi = require 'ffi' ffi.cdef[[ int open(const char* file,int flag); void *mmap (void *__addr, int __len, int __prot, int __flags, int __fd, int __offset); #pragma pack(1) typedef struct{ char name[21]; unsigned short age; unsigned short weight; }Student; ]] print(ffi.sizeof("Student")) fd = ffi.C.open("a.db",0) pmap = ffi.C.mmap(nil,ffi.sizeof('Student')*100,1,1,fd,0) ary = ffi.cast("Student*",pmap) print("name",ffi.string(ary[3].name)) print("age",ary[3].age) print("weight",ary[3].weight)  

 

 

你可能感兴趣的:(原创技术文章)