Kea  1.9.9-git
memory_segment_local.h
Go to the documentation of this file.
1 // Copyright (C) 2012-2015 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 
15 namespace isc {
16 namespace util {
17 
24 public:
28  MemorySegmentLocal() : allocated_size_(0) {
29  }
30 
32  virtual ~MemorySegmentLocal() {}
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 
84 private:
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
97 
98 // Local Variables:
99 // mode: c++
100 // End:
malloc/free based Memory Segment class
virtual void deallocate(void *ptr, size_t size)
Free/release a segment of memory.
virtual void * allocate(size_t size)
Allocate/acquire a segment of memory.
std::pair< bool, void * > NamedAddressResult
Type definition for result returned by getNamedAddress()
Memory Segment Class.
virtual ~MemorySegmentLocal()
Destructor.
Defines the logger used by the top-level component of kea-dhcp-ddns.
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 NamedAddressResult getNamedAddressImpl(const char *name) const
Local segment version of getNamedAddress.
virtual bool allMemoryDeallocated() const
Check if all allocated memory was deallocated.