-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharena.h
53 lines (40 loc) · 1.34 KB
/
arena.h
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
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.
#ifndef STORAGE_LEVELDB_UTIL_ARENA_H_
#define STORAGE_LEVELDB_UTIL_ARENA_H_
#include <vector>
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include "util/atomic.h"
#include "util/mutexlock.h"
namespace leveldb {
class Arena {
public:
Arena();
~Arena() throw ();
// Return a pointer to a newly allocated memory block of "bytes" bytes.
char* Allocate(size_t bytes);
// Allocate memory with the normal alignment guarantees provided by malloc
char* AllocateAligned(size_t bytes);
// Returns an estimate of the total memory usage of data allocated
// by the arena (including space allocated but not yet used for user
// allocations).
uint64_t MemoryUsage() { return atomic::load_64_nobarrier(&memory_usage_); }
private:
struct Block;
Block* NewBlock(size_t bytes);
char* AllocateLarge(size_t bytes);
char* AllocateFinalize(Block* b, size_t bytes);
const size_t align_;
const size_t page_size_;
uint64_t memory_usage_;
Block* blocks_;
Block* large_;
// No copying allowed
Arena(const Arena&);
void operator=(const Arena&);
};
} // namespace leveldb
#endif // STORAGE_LEVELDB_UTIL_ARENA_H_