我英语不好,我会尽力把问题说清楚。
假设我有一个结构:
struct A {
/* the first half */
int a;
int b;
/* the second half */
int c;
int d;
} ;
我们知道A的成员会在内存中连续存储。但是,我想让 A 的前半部分和后半部分存储在两个不同的内存页中,这意味着该结构体在内存中进行了分区。我怎样才能实现它?
假设struct A是linux内核中的一个结构体,所以我在内核空间中编程。内核版本为3.10。
最佳答案
如果目标是使结构内存不连续,请使用指针并执行 kmalloc。
struct first_half {
int a;
int b;
};
struct second_half {
int c;
int d;
};
struct A {
/* the first half */
struct first_half *fh;
/* the second half */
struct second_half *sh;
} ;
fh = (struct first_half *) kmalloc();
sh = (struct second_half *) kmalloc();
关于c - 如何在linux内核中将一个结构体存储在两个不同的内存页中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38588638/