/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/develop/include/rapidjson/allocators.h Source File

/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/develop/include/rapidjson/allocators.h Source File#

Composable Kernel: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/develop/include/rapidjson/allocators.h Source File
allocators.h
Go to the documentation of this file.
1 // Tencent is pleased to support the open source community by making RapidJSON available.
2 //
3 // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4 //
5 // Licensed under the MIT License (the "License"); you may not use this file except
6 // in compliance with the License. You may obtain a copy of the License at
7 //
8 // http://opensource.org/licenses/MIT
9 //
10 // Unless required by applicable law or agreed to in writing, software distributed
11 // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 // specific language governing permissions and limitations under the License.
14 
15 #ifndef RAPIDJSON_ALLOCATORS_H_
16 #define RAPIDJSON_ALLOCATORS_H_
17 
18 #include "rapidjson.h"
19 #include "internal/meta.h"
20 
21 #include <memory>
22 #include <limits>
23 
24 #if RAPIDJSON_HAS_CXX11
25 #include <type_traits>
26 #endif
27 
29 
31 // Allocator
32 
71 #ifndef RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY
72 #define RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY (64 * 1024)
73 #endif
74 
76 // CrtAllocator
77 
79 
83 {
84  public:
85  static const bool kNeedFree = true;
86  void* Malloc(size_t size)
87  {
88  if(size) // behavior of malloc(0) is implementation defined.
89  return RAPIDJSON_MALLOC(size);
90  else
91  return NULL; // standardize to returning NULL.
92  }
93  void* Realloc(void* originalPtr, size_t originalSize, size_t newSize)
94  {
95  (void)originalSize;
96  if(newSize == 0)
97  {
98  RAPIDJSON_FREE(originalPtr);
99  return NULL;
100  }
101  return RAPIDJSON_REALLOC(originalPtr, newSize);
102  }
103  static void Free(void* ptr) RAPIDJSON_NOEXCEPT { RAPIDJSON_FREE(ptr); }
104 
105  bool operator==(const CrtAllocator&) const RAPIDJSON_NOEXCEPT { return true; }
106  bool operator!=(const CrtAllocator&) const RAPIDJSON_NOEXCEPT { return false; }
107 };
108 
110 // MemoryPoolAllocator
111 
113 
128 template <typename BaseAllocator = CrtAllocator>
130 {
132 
134  struct ChunkHeader
135  {
136  size_t capacity;
137  size_t size;
138  ChunkHeader* next;
139  };
140 
141  struct SharedData
142  {
143  ChunkHeader*
144  chunkHead;
145  BaseAllocator* ownBaseAllocator;
146  size_t refcount;
147  bool ownBuffer;
148  };
149 
150  static const size_t SIZEOF_SHARED_DATA = RAPIDJSON_ALIGN(sizeof(SharedData));
151  static const size_t SIZEOF_CHUNK_HEADER = RAPIDJSON_ALIGN(sizeof(ChunkHeader));
152 
153  static inline ChunkHeader* GetChunkHead(SharedData* shared)
154  {
155  return reinterpret_cast<ChunkHeader*>(reinterpret_cast<uint8_t*>(shared) +
156  SIZEOF_SHARED_DATA);
157  }
158  static inline uint8_t* GetChunkBuffer(SharedData* shared)
159  {
160  return reinterpret_cast<uint8_t*>(shared->chunkHead) + SIZEOF_CHUNK_HEADER;
161  }
162 
163  static const size_t kDefaultChunkCapacity =
165 
166  public:
167  static const bool kNeedFree =
168  false;
169  static const bool kRefCounted =
170  true;
171 
173 
176  explicit MemoryPoolAllocator(size_t chunkSize = kDefaultChunkCapacity,
177  BaseAllocator* baseAllocator = 0)
178  : chunk_capacity_(chunkSize),
179  baseAllocator_(baseAllocator ? baseAllocator : RAPIDJSON_NEW(BaseAllocator)()),
180  shared_(static_cast<SharedData*>(
181  baseAllocator_ ? baseAllocator_->Malloc(SIZEOF_SHARED_DATA + SIZEOF_CHUNK_HEADER)
182  : 0))
183  {
184  RAPIDJSON_ASSERT(baseAllocator_ != 0);
185  RAPIDJSON_ASSERT(shared_ != 0);
186  if(baseAllocator)
187  {
188  shared_->ownBaseAllocator = 0;
189  }
190  else
191  {
192  shared_->ownBaseAllocator = baseAllocator_;
193  }
194  shared_->chunkHead = GetChunkHead(shared_);
195  shared_->chunkHead->capacity = 0;
196  shared_->chunkHead->size = 0;
197  shared_->chunkHead->next = 0;
198  shared_->ownBuffer = true;
199  shared_->refcount = 1;
200  }
201 
203 
213  MemoryPoolAllocator(void* buffer,
214  size_t size,
215  size_t chunkSize = kDefaultChunkCapacity,
216  BaseAllocator* baseAllocator = 0)
217  : chunk_capacity_(chunkSize),
218  baseAllocator_(baseAllocator),
219  shared_(static_cast<SharedData*>(AlignBuffer(buffer, size)))
220  {
221  RAPIDJSON_ASSERT(size >= SIZEOF_SHARED_DATA + SIZEOF_CHUNK_HEADER);
222  shared_->chunkHead = GetChunkHead(shared_);
223  shared_->chunkHead->capacity = size - SIZEOF_SHARED_DATA - SIZEOF_CHUNK_HEADER;
224  shared_->chunkHead->size = 0;
225  shared_->chunkHead->next = 0;
226  shared_->ownBaseAllocator = 0;
227  shared_->ownBuffer = false;
228  shared_->refcount = 1;
229  }
230 
231  MemoryPoolAllocator(const MemoryPoolAllocator& rhs) RAPIDJSON_NOEXCEPT
232  : chunk_capacity_(rhs.chunk_capacity_),
233  baseAllocator_(rhs.baseAllocator_),
234  shared_(rhs.shared_)
235  {
236  RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0);
237  ++shared_->refcount;
238  }
239  MemoryPoolAllocator& operator=(const MemoryPoolAllocator& rhs) RAPIDJSON_NOEXCEPT
240  {
241  RAPIDJSON_NOEXCEPT_ASSERT(rhs.shared_->refcount > 0);
242  ++rhs.shared_->refcount;
243  this->~MemoryPoolAllocator();
244  baseAllocator_ = rhs.baseAllocator_;
245  chunk_capacity_ = rhs.chunk_capacity_;
246  shared_ = rhs.shared_;
247  return *this;
248  }
249 
250 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
251  MemoryPoolAllocator(MemoryPoolAllocator&& rhs) RAPIDJSON_NOEXCEPT
252  : chunk_capacity_(rhs.chunk_capacity_),
253  baseAllocator_(rhs.baseAllocator_),
254  shared_(rhs.shared_)
255  {
256  RAPIDJSON_NOEXCEPT_ASSERT(rhs.shared_->refcount > 0);
257  rhs.shared_ = 0;
258  }
259  MemoryPoolAllocator& operator=(MemoryPoolAllocator&& rhs) RAPIDJSON_NOEXCEPT
260  {
261  RAPIDJSON_NOEXCEPT_ASSERT(rhs.shared_->refcount > 0);
262  this->~MemoryPoolAllocator();
263  baseAllocator_ = rhs.baseAllocator_;
264  chunk_capacity_ = rhs.chunk_capacity_;
265  shared_ = rhs.shared_;
266  rhs.shared_ = 0;
267  return *this;
268  }
269 #endif
270 
272 
274  ~MemoryPoolAllocator() RAPIDJSON_NOEXCEPT
275  {
276  if(!shared_)
277  {
278  // do nothing if moved
279  return;
280  }
281  if(shared_->refcount > 1)
282  {
283  --shared_->refcount;
284  return;
285  }
286  Clear();
287  BaseAllocator* a = shared_->ownBaseAllocator;
288  if(shared_->ownBuffer)
289  {
290  baseAllocator_->Free(shared_);
291  }
293  }
294 
296  void Clear() RAPIDJSON_NOEXCEPT
297  {
298  RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0);
299  for(;;)
300  {
301  ChunkHeader* c = shared_->chunkHead;
302  if(!c->next)
303  {
304  break;
305  }
306  shared_->chunkHead = c->next;
307  baseAllocator_->Free(c);
308  }
309  shared_->chunkHead->size = 0;
310  }
311 
313 
315  size_t Capacity() const RAPIDJSON_NOEXCEPT
316  {
317  RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0);
318  size_t capacity = 0;
319  for(ChunkHeader* c = shared_->chunkHead; c != 0; c = c->next)
320  capacity += c->capacity;
321  return capacity;
322  }
323 
325 
327  size_t Size() const RAPIDJSON_NOEXCEPT
328  {
329  RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0);
330  size_t size = 0;
331  for(ChunkHeader* c = shared_->chunkHead; c != 0; c = c->next)
332  size += c->size;
333  return size;
334  }
335 
337 
339  bool Shared() const RAPIDJSON_NOEXCEPT
340  {
341  RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0);
342  return shared_->refcount > 1;
343  }
344 
346  void* Malloc(size_t size)
347  {
348  RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0);
349  if(!size)
350  return NULL;
351 
352  size = RAPIDJSON_ALIGN(size);
353  if(RAPIDJSON_UNLIKELY(shared_->chunkHead->size + size > shared_->chunkHead->capacity))
354  if(!AddChunk(chunk_capacity_ > size ? chunk_capacity_ : size))
355  return NULL;
356 
357  void* buffer = GetChunkBuffer(shared_) + shared_->chunkHead->size;
358  shared_->chunkHead->size += size;
359  return buffer;
360  }
361 
363  void* Realloc(void* originalPtr, size_t originalSize, size_t newSize)
364  {
365  if(originalPtr == 0)
366  return Malloc(newSize);
367 
368  RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0);
369  if(newSize == 0)
370  return NULL;
371 
372  originalSize = RAPIDJSON_ALIGN(originalSize);
373  newSize = RAPIDJSON_ALIGN(newSize);
374 
375  // Do not shrink if new size is smaller than original
376  if(originalSize >= newSize)
377  return originalPtr;
378 
379  // Simply expand it if it is the last allocation and there is sufficient space
380  if(originalPtr == GetChunkBuffer(shared_) + shared_->chunkHead->size - originalSize)
381  {
382  size_t increment = static_cast<size_t>(newSize - originalSize);
383  if(shared_->chunkHead->size + increment <= shared_->chunkHead->capacity)
384  {
385  shared_->chunkHead->size += increment;
386  return originalPtr;
387  }
388  }
389 
390  // Realloc process: allocate and copy memory, do not free original buffer.
391  if(void* newBuffer = Malloc(newSize))
392  {
393  if(originalSize)
394  std::memcpy(newBuffer, originalPtr, originalSize);
395  return newBuffer;
396  }
397  else
398  return NULL;
399  }
400 
402  static void Free(void* ptr) RAPIDJSON_NOEXCEPT { (void)ptr; } // Do nothing
403 
405  bool operator==(const MemoryPoolAllocator& rhs) const RAPIDJSON_NOEXCEPT
406  {
407  RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0);
408  RAPIDJSON_NOEXCEPT_ASSERT(rhs.shared_->refcount > 0);
409  return shared_ == rhs.shared_;
410  }
412  bool operator!=(const MemoryPoolAllocator& rhs) const RAPIDJSON_NOEXCEPT
413  {
414  return !operator==(rhs);
415  }
416 
417  private:
419 
422  bool AddChunk(size_t capacity)
423  {
424  if(!baseAllocator_)
425  shared_->ownBaseAllocator = baseAllocator_ = RAPIDJSON_NEW(BaseAllocator)();
426  if(ChunkHeader* chunk =
427  static_cast<ChunkHeader*>(baseAllocator_->Malloc(SIZEOF_CHUNK_HEADER + capacity)))
428  {
429  chunk->capacity = capacity;
430  chunk->size = 0;
431  chunk->next = shared_->chunkHead;
432  shared_->chunkHead = chunk;
433  return true;
434  }
435  else
436  return false;
437  }
438 
439  static inline void* AlignBuffer(void* buf, size_t& size)
440  {
441  RAPIDJSON_NOEXCEPT_ASSERT(buf != 0);
442  const uintptr_t mask = sizeof(void*) - 1;
443  const uintptr_t ubuf = reinterpret_cast<uintptr_t>(buf);
444  if(RAPIDJSON_UNLIKELY(ubuf & mask))
445  {
446  const uintptr_t abuf = (ubuf + mask) & ~mask;
447  RAPIDJSON_ASSERT(size >= abuf - ubuf);
448  buf = reinterpret_cast<void*>(abuf);
449  size -= abuf - ubuf;
450  }
451  return buf;
452  }
453 
454  size_t chunk_capacity_;
455  BaseAllocator* baseAllocator_;
456  SharedData* shared_;
457 };
458 
459 namespace internal {
460 template <typename, typename = void>
461 struct IsRefCounted : public FalseType
462 {
463 };
464 template <typename T>
465 struct IsRefCounted<T, typename internal::EnableIfCond<T::kRefCounted>::Type> : public TrueType
466 {
467 };
468 } // namespace internal
469 
470 template <typename T, typename A>
471 inline T* Realloc(A& a, T* old_p, size_t old_n, size_t new_n)
472 {
474  new_n <= (std::numeric_limits<size_t>::max)() / sizeof(T));
475  return static_cast<T*>(a.Realloc(old_p, old_n * sizeof(T), new_n * sizeof(T)));
476 }
477 
478 template <typename T, typename A>
479 inline T* Malloc(A& a, size_t n = 1)
480 {
481  return Realloc<T, A>(a, NULL, 0, n);
482 }
483 
484 template <typename T, typename A>
485 inline void Free(A& a, T* p, size_t n = 1)
486 {
487  static_cast<void>(Realloc<T, A>(a, p, n, 0));
488 }
489 
490 #ifdef __GNUC__
491 RAPIDJSON_DIAG_PUSH
492 RAPIDJSON_DIAG_OFF(effc++) // std::allocator can safely be inherited
493 #endif
494 
495 template <typename T, typename BaseAllocator = CrtAllocator>
496 class StdAllocator : public std::allocator<T>
497 {
498  typedef std::allocator<T> allocator_type;
499 #if RAPIDJSON_HAS_CXX11
500  typedef std::allocator_traits<allocator_type> traits_type;
501 #else
502  typedef allocator_type traits_type;
503 #endif
504 
505  public:
506  typedef BaseAllocator BaseAllocatorType;
507 
508  StdAllocator() RAPIDJSON_NOEXCEPT : allocator_type(), baseAllocator_() {}
509 
510  StdAllocator(const StdAllocator& rhs) RAPIDJSON_NOEXCEPT : allocator_type(rhs),
511  baseAllocator_(rhs.baseAllocator_)
512  {
513  }
514 
515  template <typename U>
516  StdAllocator(const StdAllocator<U, BaseAllocator>& rhs) RAPIDJSON_NOEXCEPT
517  : allocator_type(rhs),
518  baseAllocator_(rhs.baseAllocator_)
519  {
520  }
521 
522 #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
523  StdAllocator(StdAllocator&& rhs) RAPIDJSON_NOEXCEPT
524  : allocator_type(std::move(rhs)),
525  baseAllocator_(std::move(rhs.baseAllocator_))
526  {
527  }
528 #endif
529 #if RAPIDJSON_HAS_CXX11
530  using propagate_on_container_move_assignment = std::true_type;
531  using propagate_on_container_swap = std::true_type;
532 #endif
533 
534  /* implicit */
535  StdAllocator(const BaseAllocator& baseAllocator) RAPIDJSON_NOEXCEPT
536  : allocator_type(),
537  baseAllocator_(baseAllocator)
538  {
539  }
540 
541  ~StdAllocator() RAPIDJSON_NOEXCEPT {}
542 
543  template <typename U>
544  struct rebind
545  {
547  };
548 
549  typedef typename traits_type::size_type size_type;
550  typedef typename traits_type::difference_type difference_type;
551 
552  typedef typename traits_type::value_type value_type;
553  typedef typename traits_type::pointer pointer;
554  typedef typename traits_type::const_pointer const_pointer;
555 
556 #if RAPIDJSON_HAS_CXX11
557 
558  typedef typename std::add_lvalue_reference<value_type>::type& reference;
559  typedef typename std::add_lvalue_reference<typename std::add_const<value_type>::type>::type&
561 
562  pointer address(reference r) const RAPIDJSON_NOEXCEPT { return std::addressof(r); }
563  const_pointer address(const_reference r) const RAPIDJSON_NOEXCEPT { return std::addressof(r); }
564 
565  size_type max_size() const RAPIDJSON_NOEXCEPT { return traits_type::max_size(*this); }
566 
567  template <typename... Args>
568  void construct(pointer p, Args&&... args)
569  {
570  traits_type::construct(*this, p, std::forward<Args>(args)...);
571  }
572  void destroy(pointer p) { traits_type::destroy(*this, p); }
573 
574 #else // !RAPIDJSON_HAS_CXX11
575 
576  typedef typename allocator_type::reference reference;
577  typedef typename allocator_type::const_reference const_reference;
578 
579  pointer address(reference r) const RAPIDJSON_NOEXCEPT { return allocator_type::address(r); }
580  const_pointer address(const_reference r) const RAPIDJSON_NOEXCEPT
581  {
582  return allocator_type::address(r);
583  }
584 
585  size_type max_size() const RAPIDJSON_NOEXCEPT { return allocator_type::max_size(); }
586 
587  void construct(pointer p, const_reference r) { allocator_type::construct(p, r); }
588  void destroy(pointer p) { allocator_type::destroy(p); }
589 
590 #endif // !RAPIDJSON_HAS_CXX11
591 
592  template <typename U>
593  U* allocate(size_type n = 1, const void* = 0)
594  {
595  return RAPIDJSON_NAMESPACE::Malloc<U>(baseAllocator_, n);
596  }
597  template <typename U>
598  void deallocate(U* p, size_type n = 1)
599  {
600  RAPIDJSON_NAMESPACE::Free<U>(baseAllocator_, p, n);
601  }
602 
603  pointer allocate(size_type n = 1, const void* = 0) { return allocate<value_type>(n); }
604  void deallocate(pointer p, size_type n = 1) { deallocate<value_type>(p, n); }
605 
606 #if RAPIDJSON_HAS_CXX11
607  using is_always_equal = std::is_empty<BaseAllocator>;
608 #endif
609 
610  template <typename U>
611  bool operator==(const StdAllocator<U, BaseAllocator>& rhs) const RAPIDJSON_NOEXCEPT
612  {
613  return baseAllocator_ == rhs.baseAllocator_;
614  }
615  template <typename U>
616  bool operator!=(const StdAllocator<U, BaseAllocator>& rhs) const RAPIDJSON_NOEXCEPT
617  {
618  return !operator==(rhs);
619  }
620 
622  static const bool kNeedFree = BaseAllocator::kNeedFree;
624  void* Malloc(size_t size) { return baseAllocator_.Malloc(size); }
625  void* Realloc(void* originalPtr, size_t originalSize, size_t newSize)
626  {
627  return baseAllocator_.Realloc(originalPtr, originalSize, newSize);
628  }
629  static void Free(void* ptr) RAPIDJSON_NOEXCEPT { BaseAllocator::Free(ptr); }
630 
631  private:
632  template <typename, typename>
633  friend class StdAllocator; // access to StdAllocator<!T>.*
634 
635  BaseAllocator baseAllocator_;
636 };
637 
638 #if !RAPIDJSON_HAS_CXX17 // std::allocator<void> deprecated in C++17
639 template <typename BaseAllocator>
640 class StdAllocator<void, BaseAllocator> : public std::allocator<void>
641 {
642  typedef std::allocator<void> allocator_type;
643 
644  public:
645  typedef BaseAllocator BaseAllocatorType;
646 
647  StdAllocator() RAPIDJSON_NOEXCEPT : allocator_type(), baseAllocator_() {}
648 
649  StdAllocator(const StdAllocator& rhs) RAPIDJSON_NOEXCEPT : allocator_type(rhs),
650  baseAllocator_(rhs.baseAllocator_)
651  {
652  }
653 
654  template <typename U>
655  StdAllocator(const StdAllocator<U, BaseAllocator>& rhs) RAPIDJSON_NOEXCEPT
656  : allocator_type(rhs),
657  baseAllocator_(rhs.baseAllocator_)
658  {
659  }
660 
661  /* implicit */
662  StdAllocator(const BaseAllocator& baseAllocator) RAPIDJSON_NOEXCEPT
663  : allocator_type(),
664  baseAllocator_(baseAllocator)
665  {
666  }
667 
668  ~StdAllocator() RAPIDJSON_NOEXCEPT {}
669 
670  template <typename U>
671  struct rebind
672  {
674  };
675 
676  typedef typename allocator_type::value_type value_type;
677 
678  private:
679  template <typename, typename>
680  friend class StdAllocator; // access to StdAllocator<!T>.*
681 
682  BaseAllocator baseAllocator_;
683 };
684 #endif
685 
686 #ifdef __GNUC__
687 RAPIDJSON_DIAG_POP
688 #endif
689 
691 
692 #endif // RAPIDJSON_ENCODINGS_H_
T * Realloc(A &a, T *old_p, size_t old_n, size_t new_n)
Definition: allocators.h:471
void Free(A &a, T *p, size_t n=1)
Definition: allocators.h:485
T * Malloc(A &a, size_t n=1)
Definition: allocators.h:479
C-runtime library allocator.
Definition: allocators.h:83
bool operator!=(const CrtAllocator &) const RAPIDJSON_NOEXCEPT
Definition: allocators.h:106
void * Realloc(void *originalPtr, size_t originalSize, size_t newSize)
Definition: allocators.h:93
static void Free(void *ptr) RAPIDJSON_NOEXCEPT
Definition: allocators.h:103
static const bool kNeedFree
Definition: allocators.h:85
void * Malloc(size_t size)
Definition: allocators.h:86
bool operator==(const CrtAllocator &) const RAPIDJSON_NOEXCEPT
Definition: allocators.h:105
Default memory allocator used by the parser and DOM.
Definition: allocators.h:130
void * Malloc(size_t size)
Allocates a memory block. (concept Allocator)
Definition: allocators.h:346
MemoryPoolAllocator(void *buffer, size_t size, size_t chunkSize=kDefaultChunkCapacity, BaseAllocator *baseAllocator=0)
Constructor with user-supplied buffer.
Definition: allocators.h:213
MemoryPoolAllocator & operator=(const MemoryPoolAllocator &rhs) RAPIDJSON_NOEXCEPT
Definition: allocators.h:239
static const bool kRefCounted
Tell users that this allocator is reference counted on copy.
Definition: allocators.h:169
size_t Size() const RAPIDJSON_NOEXCEPT
Computes the memory blocks allocated.
Definition: allocators.h:327
size_t Capacity() const RAPIDJSON_NOEXCEPT
Computes the total capacity of allocated memory chunks.
Definition: allocators.h:315
void Clear() RAPIDJSON_NOEXCEPT
Deallocates all memory chunks, excluding the first/user one.
Definition: allocators.h:296
bool operator==(const MemoryPoolAllocator &rhs) const RAPIDJSON_NOEXCEPT
Compare (equality) with another MemoryPoolAllocator.
Definition: allocators.h:405
static void Free(void *ptr) RAPIDJSON_NOEXCEPT
Frees a memory block (concept Allocator)
Definition: allocators.h:402
static const bool kNeedFree
Tell users that no need to call Free() with this allocator. (concept Allocator)
Definition: allocators.h:167
bool operator!=(const MemoryPoolAllocator &rhs) const RAPIDJSON_NOEXCEPT
Compare (inequality) with another MemoryPoolAllocator.
Definition: allocators.h:412
void * Realloc(void *originalPtr, size_t originalSize, size_t newSize)
Resizes a memory block (concept Allocator)
Definition: allocators.h:363
bool Shared() const RAPIDJSON_NOEXCEPT
Whether the allocator is shared.
Definition: allocators.h:339
MemoryPoolAllocator(size_t chunkSize=kDefaultChunkCapacity, BaseAllocator *baseAllocator=0)
Constructor with chunkSize.
Definition: allocators.h:176
MemoryPoolAllocator(const MemoryPoolAllocator &rhs) RAPIDJSON_NOEXCEPT
Definition: allocators.h:231
~MemoryPoolAllocator() RAPIDJSON_NOEXCEPT
Destructor.
Definition: allocators.h:274
allocator_type::value_type value_type
Definition: allocators.h:676
~StdAllocator() RAPIDJSON_NOEXCEPT
Definition: allocators.h:668
StdAllocator(const StdAllocator< U, BaseAllocator > &rhs) RAPIDJSON_NOEXCEPT
Definition: allocators.h:655
BaseAllocator BaseAllocatorType
Definition: allocators.h:645
StdAllocator(const BaseAllocator &baseAllocator) RAPIDJSON_NOEXCEPT
Definition: allocators.h:662
StdAllocator(const StdAllocator &rhs) RAPIDJSON_NOEXCEPT
Definition: allocators.h:649
StdAllocator() RAPIDJSON_NOEXCEPT
Definition: allocators.h:647
Definition: allocators.h:497
BaseAllocator BaseAllocatorType
Definition: allocators.h:506
traits_type::pointer pointer
Definition: allocators.h:553
allocator_type::reference reference
Definition: allocators.h:576
size_type max_size() const RAPIDJSON_NOEXCEPT
Definition: allocators.h:585
void construct(pointer p, const_reference r)
Definition: allocators.h:587
void destroy(pointer p)
Definition: allocators.h:588
allocator_type::const_reference const_reference
Definition: allocators.h:577
~StdAllocator() RAPIDJSON_NOEXCEPT
Definition: allocators.h:541
traits_type::difference_type difference_type
Definition: allocators.h:550
const_pointer address(const_reference r) const RAPIDJSON_NOEXCEPT
Definition: allocators.h:580
bool operator!=(const StdAllocator< U, BaseAllocator > &rhs) const RAPIDJSON_NOEXCEPT
Definition: allocators.h:616
static const bool kNeedFree
rapidjson Allocator concept
Definition: allocators.h:622
void deallocate(U *p, size_type n=1)
Definition: allocators.h:598
void deallocate(pointer p, size_type n=1)
Definition: allocators.h:604
void * Realloc(void *originalPtr, size_t originalSize, size_t newSize)
Definition: allocators.h:625
pointer allocate(size_type n=1, const void *=0)
Definition: allocators.h:603
traits_type::value_type value_type
Definition: allocators.h:552
StdAllocator(const BaseAllocator &baseAllocator) RAPIDJSON_NOEXCEPT
Definition: allocators.h:535
StdAllocator(const StdAllocator< U, BaseAllocator > &rhs) RAPIDJSON_NOEXCEPT
Definition: allocators.h:516
StdAllocator(const StdAllocator &rhs) RAPIDJSON_NOEXCEPT
Definition: allocators.h:510
void * Malloc(size_t size)
Definition: allocators.h:624
bool operator==(const StdAllocator< U, BaseAllocator > &rhs) const RAPIDJSON_NOEXCEPT
Definition: allocators.h:611
traits_type::const_pointer const_pointer
Definition: allocators.h:554
static void Free(void *ptr) RAPIDJSON_NOEXCEPT
Definition: allocators.h:629
traits_type::size_type size_type
Definition: allocators.h:549
U * allocate(size_type n=1, const void *=0)
Definition: allocators.h:593
friend class StdAllocator
Definition: allocators.h:633
pointer address(reference r) const RAPIDJSON_NOEXCEPT
Definition: allocators.h:579
static const bool kRefCounted
Definition: allocators.h:623
StdAllocator() RAPIDJSON_NOEXCEPT
Definition: allocators.h:508
#define RAPIDJSON_NOEXCEPT_ASSERT(x)
Assertion (in non-throwing contexts).
Definition: rapidjson.h:717
#define RAPIDJSON_ALIGN(x)
Data alignment of the machine.
Definition: rapidjson.h:313
#define RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
Definition: rapidjson.h:531
#define RAPIDJSON_ALLOCATOR_DEFAULT_CHUNK_CAPACITY
User-defined kDefaultChunkCapacity definition.
Definition: allocators.h:72
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:451
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:121
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:124
__host__ constexpr __device__ T max(T x)
Definition: math.hpp:84
bool_constant< true > true_type
Definition: integral_constant.hpp:62
Definition: allocators.h:459
const GenericPointer< typename T::ValueType > & pointer
Definition: pointer.h:1514
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1517
common definitions and configuration
#define RAPIDJSON_MALLOC(size)
! customization point for global malloc
Definition: rapidjson.h:726
Type
Type of JSON value.
Definition: rapidjson.h:760
#define RAPIDJSON_DELETE(x)
! customization point for global delete
Definition: rapidjson.h:746
#define RAPIDJSON_REALLOC(ptr, new_size)
! customization point for global realloc
Definition: rapidjson.h:730
#define RAPIDJSON_FREE(ptr)
! customization point for global free
Definition: rapidjson.h:734
#define RAPIDJSON_NEW(TypeName)
! customization point for global new
Definition: rapidjson.h:742
_W64 unsigned int uintptr_t
Definition: stdint.h:164
unsigned char uint8_t
Definition: stdint.h:124
Definition: allocators.h:545
StdAllocator< U, BaseAllocator > other
Definition: allocators.h:546
StdAllocator< U, BaseAllocator > other
Definition: allocators.h:673
Definition: allocators.h:462