blob: 110c9b39371beba09916a08d2a0920f4c8553553 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MOJO_PUBLIC_CPP_BINDINGS_ALLOCATION_SCOPE_H_
#define MOJO_PUBLIC_CPP_BINDINGS_ALLOCATION_SCOPE_H_
#include "mojo/public/cpp/bindings/lib/scratch_buffer.h"
#include "mojo/public/cpp/system/macros.h"
namespace mojo {
// In order to allocate a Mojom-defined structure or mojo::Array<T> (including
// mojo::String), an AllocationScope must first be allocated. Typically,
// AllocationScope is placed on the stack before calls to build structs and
// arrays. Such structs and arrays are valid so long as the corresponding
// AllocationScope remains alive.
//
// AllocationScope instantiates a Buffer and sets it in thread local storage.
// This Buffer instance can be retrieved using Buffer::current().
//
// EXAMPLE:
//
// mojo::AllocationScope scope;
// mojo::String s = "hello world";
// some_interface->SomeMethod(s);
//
class AllocationScope {
public:
AllocationScope() {}
~AllocationScope() {}
Buffer* buffer() { return &buffer_; }
private:
internal::ScratchBuffer buffer_;
MOJO_DISALLOW_COPY_AND_ASSIGN(AllocationScope);
};
} // namespace mojo
#endif // MOJO_PUBLIC_CPP_BINDINGS_ALLOCATION_SCOPE_H_
|