Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(664)

Side by Side Diff: base/allocator/partition_allocator/partition_alloc.h

Issue 2870213002: Update the PartitionAlloc documentation. (Closed)
Patch Set: Respond to comments. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_H 5 #ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_H
6 #define BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_H 6 #define BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_H
7 7
8 // DESCRIPTION 8 // DESCRIPTION
9 // partitionAlloc() / PartitionAllocGeneric() and PartitionFree() / 9 // partitionAlloc() / PartitionAllocGeneric() and PartitionFree() /
10 // PartitionFreeGeneric() are approximately analagous to malloc() and free(). 10 // PartitionFreeGeneric() are approximately analagous to malloc() and free().
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 // No need to lock here. Only |ptr| being freed by another thread could 867 // No need to lock here. Only |ptr| being freed by another thread could
868 // cause trouble, and the caller is responsible for that not happening. 868 // cause trouble, and the caller is responsible for that not happening.
869 DCHECK(PartitionAllocSupportsGetSize()); 869 DCHECK(PartitionAllocSupportsGetSize());
870 ptr = PartitionCookieFreePointerAdjust(ptr); 870 ptr = PartitionCookieFreePointerAdjust(ptr);
871 DCHECK(PartitionPointerIsValid(ptr)); 871 DCHECK(PartitionPointerIsValid(ptr));
872 PartitionPage* page = PartitionPointerToPage(ptr); 872 PartitionPage* page = PartitionPointerToPage(ptr);
873 size_t size = page->bucket->slot_size; 873 size_t size = page->bucket->slot_size;
874 return PartitionCookieSizeAdjustSubtract(size); 874 return PartitionCookieSizeAdjustSubtract(size);
875 } 875 }
876 876
877 // N (or more accurately, N - sizeof(void*)) represents the largest size in
878 // bytes that will be handled by a SizeSpecificPartitionAllocator.
879 // Attempts to partitionAlloc() more than this amount will fail.
880 template <size_t N> 877 template <size_t N>
881 class SizeSpecificPartitionAllocator { 878 class SizeSpecificPartitionAllocator {
882 public: 879 public:
883 static const size_t kMaxAllocation = N - kAllocationGranularity; 880 static const size_t kMaxAllocation = N - kAllocationGranularity;
884 static const size_t kNumBuckets = N / kAllocationGranularity; 881 static const size_t kNumBuckets = N / kAllocationGranularity;
885 void init() { 882 void init() {
886 PartitionAllocInit(&partition_root_, kNumBuckets, kMaxAllocation); 883 PartitionAllocInit(&partition_root_, kNumBuckets, kMaxAllocation);
887 } 884 }
888 ALWAYS_INLINE PartitionRoot* root() { return &partition_root_; } 885 ALWAYS_INLINE PartitionRoot* root() { return &partition_root_; }
889 886
890 private: 887 private:
891 PartitionRoot partition_root_; 888 PartitionRoot partition_root_;
892 PartitionBucket actual_buckets_[kNumBuckets]; 889 PartitionBucket actual_buckets_[kNumBuckets];
893 }; 890 };
894 891
895 class PartitionAllocatorGeneric { 892 class PartitionAllocatorGeneric {
896 public: 893 public:
897 void init() { PartitionAllocGenericInit(&partition_root_); } 894 void init() { PartitionAllocGenericInit(&partition_root_); }
898 ALWAYS_INLINE PartitionRootGeneric* root() { return &partition_root_; } 895 ALWAYS_INLINE PartitionRootGeneric* root() { return &partition_root_; }
899 896
900 private: 897 private:
901 PartitionRootGeneric partition_root_; 898 PartitionRootGeneric partition_root_;
902 }; 899 };
903 900
904 } // namespace base 901 } // namespace base
905 902
906 #endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_H 903 #endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_H
OLDNEW
« no previous file with comments | « base/allocator/partition_allocator/PartitionAlloc.md ('k') | third_party/WebKit/Source/platform/wtf/allocator/Allocator.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698