1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef MOJO_PUBLIC_BINDINGS_LIB_SCRATCH_BUFFER_H_
6 #define MOJO_PUBLIC_BINDINGS_LIB_SCRATCH_BUFFER_H_
10 #include "mojo/public/bindings/buffer.h"
11 #include "mojo/public/system/macros.h"
16 // The following class is designed to be allocated on the stack. If necessary,
17 // it will failover to allocating objects on the heap.
18 class ScratchBuffer : public Buffer {
21 virtual ~ScratchBuffer();
23 virtual void* Allocate(size_t num_bytes, Destructor func = NULL)
27 enum { kMinSegmentSize = 512 };
35 void* AllocateInSegment(Segment* segment, size_t num_bytes);
36 void AddOverflowSegment(size_t delta);
38 char fixed_data_[kMinSegmentSize];
42 struct PendingDestructor {
46 std::deque<PendingDestructor> pending_dtors_;
48 MOJO_DISALLOW_COPY_AND_ASSIGN(ScratchBuffer);
51 } // namespace internal
54 #endif // MOJO_PUBLIC_BINDINGS_LIB_SCRATCH_BUFFER_H_