Add an allocate() member function on IOBufQueue
authorTudor Bosman <tudorb@fb.com>
Wed, 13 Jun 2012 23:52:38 +0000 (16:52 -0700)
committerJordan DeLong <jdelong@fb.com>
Fri, 22 Jun 2012 02:38:37 +0000 (19:38 -0700)
Summary: Function is documented in the header.

Reviewed By: soren@fb.com

FB internal diff: D494315

folly/experimental/io/IOBufQueue.h

index 7c25c62157eaa999e264143b5b25d16234c1ca4d..283cd3ac5d7ea360b4f704d73d98e7942ae3e99c 100644 (file)
@@ -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