SmallLeafHeapBlock.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #include "CommonMemoryPch.h"
  6. template <class TBlockAttributes>
  7. SmallLeafHeapBlockT<TBlockAttributes> *
  8. SmallLeafHeapBlockT<TBlockAttributes>::New(HeapBucketT<SmallLeafHeapBlockT<TBlockAttributes>> * bucket)
  9. {
  10. CompileAssert(TBlockAttributes::MaxObjectSize <= USHRT_MAX);
  11. Assert(bucket->sizeCat <= TBlockAttributes::MaxObjectSize);
  12. Assert((TBlockAttributes::PageCount * AutoSystemInfo::PageSize) / bucket->sizeCat <= USHRT_MAX);
  13. ushort objectSize = (ushort)bucket->sizeCat;
  14. ushort objectCount = (ushort)(TBlockAttributes::PageCount * AutoSystemInfo::PageSize) / objectSize;
  15. return NoMemProtectHeapNewNoThrowPlusPrefixZ(Base::GetAllocPlusSize(objectCount), SmallLeafHeapBlockT<TBlockAttributes>, bucket, objectSize, objectCount);
  16. }
  17. template <>
  18. SmallLeafHeapBlockT<SmallAllocationBlockAttributes>::SmallLeafHeapBlockT(HeapBucketT<SmallLeafHeapBlockT<SmallAllocationBlockAttributes>> * bucket, ushort objectSize, ushort objectCount)
  19. : Base(bucket, objectSize, objectCount, HeapBlock::HeapBlockType::SmallLeafBlockType)
  20. {
  21. Assert(objectCount > 1 && objectCount == (this->GetPageCount() * AutoSystemInfo::PageSize)/ objectSize);
  22. }
  23. template <>
  24. SmallLeafHeapBlockT<MediumAllocationBlockAttributes>::SmallLeafHeapBlockT(HeapBucketT<SmallLeafHeapBlockT<MediumAllocationBlockAttributes>> * bucket, ushort objectSize, ushort objectCount)
  25. : Base(bucket, objectSize, objectCount, HeapBlock::HeapBlockType::MediumLeafBlockType)
  26. {
  27. Assert(objectCount > 1 && objectCount == (this->GetPageCount() * AutoSystemInfo::PageSize) / objectSize);
  28. }
  29. template <class TBlockAttributes>
  30. void
  31. SmallLeafHeapBlockT<TBlockAttributes>::Delete(SmallLeafHeapBlockT<TBlockAttributes> * heapBlock)
  32. {
  33. Assert(heapBlock->IsLeafBlock());
  34. NoMemProtectHeapDeletePlusPrefix(Base::GetAllocPlusSize(heapBlock->objectCount), heapBlock);
  35. }
  36. template <class TBlockAttributes>
  37. void
  38. SmallLeafHeapBlockT<TBlockAttributes>::ScanNewImplicitRoots(Recycler * recycler)
  39. {
  40. Base::ScanNewImplicitRootsBase([](void * object, size_t objectSize){});
  41. }
  42. #ifdef RECYCLER_SLOW_CHECK_ENABLED
  43. template <class TBlockAttributes>
  44. bool
  45. SmallLeafHeapBlockT<TBlockAttributes>::GetFreeObjectListOnAllocator(FreeObject ** freeObjectList)
  46. {
  47. return this->template GetFreeObjectListOnAllocatorImpl<SmallLeafHeapBlockT<TBlockAttributes>>(freeObjectList);
  48. }
  49. #endif
  50. namespace Memory
  51. {
  52. // Declare the class templates
  53. template class SmallLeafHeapBlockT<SmallAllocationBlockAttributes>;
  54. template class SmallLeafHeapBlockT<MediumAllocationBlockAttributes>;
  55. }