Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSLMemoryPool.h
Go to the documentation of this file.
1/*
2 * Copyright 2020 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SKSL_MEMORYPOOL
9#define SKSL_MEMORYPOOL
10
11#include <memory>
12
15
16namespace SkSL {
17
19public:
20 static std::unique_ptr<MemoryPool> Make() {
21 return std::make_unique<MemoryPool>();
22 }
23 void* allocate(size_t size) {
24 return fArena.makeBytesAlignedTo(size, kAlignment);
25 }
26 void release(void*) {
27 // SkArenaAlloc does not ever attempt to reclaim space.
28 }
29
30private:
31#ifdef SK_FORCE_8_BYTE_ALIGNMENT
32 // https://github.com/emscripten-core/emscripten/issues/10072
33 // Since Skia does not use "long double" (16 bytes), we should be ok to force it back to 8 bytes
34 // until emscripten is fixed.
35 static constexpr size_t kAlignment = 8;
36#else
37 // Guaranteed alignment of pointer returned by allocate().
38 static constexpr size_t kAlignment = alignof(std::max_align_t);
39#endif
40
41 SkSTArenaAlloc<65536> fArena{/*firstHeapAllocation=*/32768};
42};
43
44} // namespace SkSL
45
46#endif // SKSL_MEMORYPOOL
void * makeBytesAlignedTo(size_t size, size_t align)
static std::unique_ptr< MemoryPool > Make()
void release(void *)
void * allocate(size_t size)