Kea 2.7.5
memory_segment_local.h
Go to the documentation of this file.
1// Copyright (C) 2012-2024 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef MEMORY_SEGMENT_LOCAL_H
8#define MEMORY_SEGMENT_LOCAL_H
9
10#include <util/memory_segment.h>
11
12#include <string>
13#include <map>
14
15namespace isc {
16namespace util {
17
24public:
28 MemorySegmentLocal() : allocated_size_(0) {
29 }
30
33
42 virtual void* allocate(size_t size);
43
53 virtual void deallocate(void* ptr, size_t size);
54
59 virtual bool allMemoryDeallocated() const;
60
65 virtual NamedAddressResult getNamedAddressImpl(const char* name) const;
66
76 virtual bool setNamedAddressImpl(const char* name, void* addr);
77
82 virtual bool clearNamedAddressImpl(const char* name);
83
84private:
85 // allocated_size_ can underflow, wrap around to max size_t (which
86 // is unsigned). But because we only do a check against 0 and not a
87 // relation comparison, this is okay.
88 size_t allocated_size_;
89
90 std::map<std::string, void*> named_addrs_;
91};
92
93} // namespace util
94} // namespace isc
95
96#endif // MEMORY_SEGMENT_LOCAL_H
malloc/free based Memory Segment class
virtual bool setNamedAddressImpl(const char *name, void *addr)
Local segment version of setNamedAddress.
virtual bool clearNamedAddressImpl(const char *name)
Local segment version of clearNamedAddress.
virtual void * allocate(size_t size)
Allocate/acquire a segment of memory.
virtual bool allMemoryDeallocated() const
Check if all allocated memory was deallocated.
virtual ~MemorySegmentLocal()
Destructor.
virtual NamedAddressResult getNamedAddressImpl(const char *name) const
Local segment version of getNamedAddress.
virtual void deallocate(void *ptr, size_t size)
Free/release a segment of memory.
Memory Segment Class.
std::pair< bool, void * > NamedAddressResult
Type definition for result returned by getNamedAddress()
Defines the logger used by the top-level component of kea-lfc.