From 62072424464bf9831aa899f23484d7b8c54daac6 Mon Sep 17 00:00:00 2001 From: Tudor Bosman Date: Wed, 13 Jun 2012 16:52:38 -0700 Subject: [PATCH] Add an allocate() member function on IOBufQueue Summary: Function is documented in the header. Reviewed By: soren@fb.com FB internal diff: D494315 --- folly/experimental/io/IOBufQueue.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/folly/experimental/io/IOBufQueue.h b/folly/experimental/io/IOBufQueue.h index 7c25c621..283cd3ac 100644 --- a/folly/experimental/io/IOBufQueue.h +++ b/folly/experimental/io/IOBufQueue.h @@ -114,6 +114,16 @@ class IOBufQueue { */ void postallocate(uint32_t n); + /** + * Obtain a writable block of n contiguous bytes, allocating more space + * if necessary, and mark it as used. The caller can fill it later. + */ + void* allocate(uint32_t n) { + void* p = preallocate(n, n).first; + postallocate(n); + return p; + } + /** * Split off the first n bytes of the queue into a separate IOBuf chain, * and transfer ownership of the new chain to the caller. The IOBufQueue -- 2.34.1