OLD | NEW |
| (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_BINDINGS_ALLOCATION_SCOPE_H_ | |
6 #define MOJO_PUBLIC_BINDINGS_ALLOCATION_SCOPE_H_ | |
7 | |
8 #include "mojo/public/bindings/lib/scratch_buffer.h" | |
9 #include "mojo/public/cpp/system/macros.h" | |
10 | |
11 namespace mojo { | |
12 | |
13 // In order to allocate a Mojom-defined structure or mojo::Array<T> (including | |
14 // mojo::String), an AllocationScope must first be allocated. Typically, | |
15 // AllocationScope is placed on the stack before calls to build structs and | |
16 // arrays. Such structs and arrays are valid so long as the corresponding | |
17 // AllocationScope remains alive. | |
18 // | |
19 // AllocationScope instantiates a Buffer and sets it in thread local storage. | |
20 // This Buffer instance can be retrieved using Buffer::current(). | |
21 // | |
22 // EXAMPLE: | |
23 // | |
24 // mojo::AllocationScope scope; | |
25 // mojo::String s = "hello world"; | |
26 // some_interface->SomeMethod(s); | |
27 // | |
28 class AllocationScope { | |
29 public: | |
30 AllocationScope() {} | |
31 ~AllocationScope() {} | |
32 | |
33 Buffer* buffer() { return &buffer_; } | |
34 | |
35 private: | |
36 internal::ScratchBuffer buffer_; | |
37 | |
38 MOJO_DISALLOW_COPY_AND_ASSIGN(AllocationScope); | |
39 }; | |
40 | |
41 } // namespace mojo | |
42 | |
43 #endif // MOJO_PUBLIC_BINDINGS_ALLOCATION_SCOPE_H_ | |
OLD | NEW |