我正在使用and开发一个c
程序。libuv
jemalloc
当je_malloc调用了大约3735次(大约占用600 MB内存)。
我的静态变量sa_socket-> nread=0,len=0,handle=0x200000000
,所以调用uv_write
时会sa_socket->handle
引发错误EFAULT: bad address in system call argument
。
#define BUFF_LEN (128*1024)
typedef struct {
char buff[BUFF_LEN];
size_t len;
uv_stream_t* handle;
size_t nread;
} socket_info;
static socket_info *sa_socket;
static void alloc_cb(uv_handle_t *handle, size_t size, uv_buf_t *buf) {
buf->base = sa_socket->buff + sa_socket->nread;
buf->len = sa_socket->len - sa_socket->nread;
}
void init() {
uv_replace_allocator(je_malloc,je_realloc,je_calloc,je_free);
sa_socket = je_malloc(sizeof(sa_socket));
sa_socket->nread = 0;
sa_socket->len = BUFF_LEN;
....
}