OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 #include <cstdlib> | |
6 | |
7 #include "base/logging.h" | |
8 #include "services/media/framework/allocator.h" | |
9 | |
10 namespace mojo { | |
11 namespace media { | |
12 | |
13 namespace { | |
14 | |
15 class DefaultAllocator : public Allocator { | |
16 public: | |
17 constexpr DefaultAllocator() {} | |
jeffbrown
2016/02/02 05:35:45
constexpr isn't appropriate here
johngro
2016/02/02 17:21:37
constexpr is required here to satisfy style. Late
dalesat
2016/02/02 21:46:38
Acknowledged.
| |
18 | |
19 // Allocator implementation. | |
20 void* AllocatePayloadBuffer(uint64_t size) override; | |
21 | |
22 void ReleasePayloadBuffer(uint64_t size, void* buffer) override; | |
23 }; | |
24 | |
25 void* DefaultAllocator::AllocatePayloadBuffer(uint64_t size) { | |
26 DCHECK(size > 0); | |
jeffbrown
2016/02/02 05:35:45
Why can't the size be zero? malloc allows this, t
dalesat
2016/02/02 21:46:38
I'd be OK with it, but I'd want to return nullptr.
| |
27 return std::malloc(static_cast<size_t>(size)); | |
28 } | |
29 | |
30 void DefaultAllocator::ReleasePayloadBuffer(uint64_t size, void* buffer) { | |
31 DCHECK(size > 0); | |
32 DCHECK(buffer); | |
33 std::free(buffer); | |
34 } | |
35 | |
36 static constexpr DefaultAllocator default_allocator; | |
jeffbrown
2016/02/02 05:35:46
I don't think you want constexpr here since this i
johngro
2016/02/02 17:21:37
See comment above. This is mandated by style, and
dalesat
2016/02/02 21:46:38
Acknowledged.
| |
37 | |
38 } // namespace | |
39 | |
40 // static | |
41 Allocator* Allocator::GetDefault() { | |
42 return const_cast<DefaultAllocator*>(&default_allocator); | |
43 } | |
44 | |
45 } // namespace media | |
46 } // namespace mojo | |
OLD | NEW |