1. 使用malloc申请一块空间,模拟KV存储的一个节点存储数据信息。
#include<stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/resource.h> typedef struct v_block *p_block;
struct v_block{ p_block next;
int free;
char *key;
char *value;
char data[]; }; int main() {
p_block pmem=(p_block)malloc();
pmem->next=;
pmem->free=;
pmem->key=pmem->data;
int i;
char *s="one";
for(i=;i<;i++) {
*(pmem->key+i)=s[i];
}
pmem->value=pmem->key+;
char *va="this is a value";
for(i=;i<;i++) {
*(pmem->value+i)=va[i];
} printf("%s ",pmem->value);
printf("%s ",pmem->key);
return ;
}