summaryrefslogtreecommitdiff
path: root/examples/link-cp.c
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2019-05-15 14:11:10 -0600
committerJens Axboe <axboe@kernel.dk>2019-05-15 14:11:10 -0600
commit95118636588d9992f59a81193ba42335223eef13 (patch)
tree4eb91caa434a4cba349bbc1dbddb46b8bf24c7ae /examples/link-cp.c
parent5c6e5d27451267c650d88a70a0f49563383d40c5 (diff)
downloadliburing-95118636588d9992f59a81193ba42335223eef13.tar.gz
liburing-95118636588d9992f59a81193ba42335223eef13.tar.bz2
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 <axboe@kernel.dk>
Diffstat (limited to 'examples/link-cp.c')
-rw-r--r--examples/link-cp.c13
1 files 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;
}