Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: mojo/public/cpp/bindings/lib/scratch_buffer.h

Issue 294833002: Mojo: more idiomatic C++ bindings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix windows bustage Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_SCRATCH_BUFFER_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_SCRATCH_BUFFER_H_
7
8 #include <deque>
9
10 #include "mojo/public/cpp/bindings/buffer.h"
11 #include "mojo/public/cpp/system/macros.h"
12
13 namespace mojo {
14 namespace internal {
15
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 {
19 public:
20 ScratchBuffer();
21 virtual ~ScratchBuffer();
22
23 virtual void* Allocate(size_t num_bytes, Destructor func = NULL)
24 MOJO_OVERRIDE;
25
26 private:
27 enum {
28 kMinSegmentSize = 512,
29 kMaxSegmentSize = 1024 * 1024 * 1024,
30 };
31
32 struct Segment {
33 Segment* next;
34 char* cursor;
35 char* end;
36 };
37
38 void* AllocateInSegment(Segment* segment, size_t num_bytes);
39 bool AddOverflowSegment(size_t delta);
40
41 char fixed_data_[kMinSegmentSize];
42 Segment fixed_;
43 Segment* overflow_;
44
45 struct PendingDestructor {
46 Destructor func;
47 void* address;
48 };
49 std::deque<PendingDestructor> pending_dtors_;
50
51 MOJO_DISALLOW_COPY_AND_ASSIGN(ScratchBuffer);
52 };
53
54 } // namespace internal
55 } // namespace mojo
56
57 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_SCRATCH_BUFFER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698