From 95118636588d9992f59a81193ba42335223eef13 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Wed, 15 May 2019 14:11:10 -0600 Subject: examples/link-cp: improve memory use Put the data at the end so we don't have to offset the actual buffer. Signed-off-by: Jens Axboe --- examples/link-cp.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/examples/link-cp.c b/examples/link-cp.c index 8f29956..a4c02e5 100644 --- a/examples/link-cp.c +++ b/examples/link-cp.c @@ -66,11 +66,13 @@ static void queue_rw_pair(struct io_uring *ring, off_t size, off_t offset) { struct io_uring_sqe *sqe; struct io_data *data; + void *ptr; - data = malloc(size + sizeof(*data)); + ptr = malloc(size + sizeof(*data)); + data = ptr + size; data->index = 0; data->offset = offset; - data->iov.iov_base = data + 1; + data->iov.iov_base = ptr; data->iov.iov_len = size; sqe = io_uring_get_sqe(ring); @@ -100,8 +102,11 @@ static int handle_cqe(struct io_uring *ring, struct io_uring_cqe *cqe) } } - if (data->index == 2) - free(data); + if (data->index == 2) { + void *ptr = (void *) data - data->iov.iov_len; + + free(ptr); + } io_uring_cqe_seen(ring, cqe); return ret; } -- cgit