From 9218d04b9a64e5eb73c53c1a523b6c76357bd90c Mon Sep 17 00:00:00 2001 From: Eugeny Maltchikov Date: Mon, 12 Sep 2022 11:00:49 +0300 Subject: [PATCH] 0033138: [Foundation Classes] - NCollection_IncAllocator- Decrease the default block size Set default memory block size for IncAllocator to 12KB to make sure the Low Fragmentation Heap is used for memory allocations on Windows platform. --- .../foundation_classes/foundation_classes.md | 2 +- src/NCollection/NCollection_IncAllocator.hxx | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/dox/user_guides/foundation_classes/foundation_classes.md b/dox/user_guides/foundation_classes/foundation_classes.md index 75ee0e41db..83ac31168b 100644 --- a/dox/user_guides/foundation_classes/foundation_classes.md +++ b/dox/user_guides/foundation_classes/foundation_classes.md @@ -1331,7 +1331,7 @@ Therefore if the user of *NCollection* does not specify any allocator as a param Nevertheless, it is possible to define a custom *Allocator* type to manage the memory in the most optimal or convenient way for this algorithm. As one possible choice, the class *NCollection_IncAllocator* is included. -Unlike *NCollection_BaseAllocator*, the memory is allocated in big blocks (about 20kB) and the allocator keeps track of the amount of occupied memory. +Unlike *NCollection_BaseAllocator*, the memory is allocated in big blocks (about 12kB) and the allocator keeps track of the amount of occupied memory. The method *Allocate* just increments the pointer to non-occupied memory and returns its previous value. Memory is only released in the destructor of *NCollection_IncAllocator*, the method *Free* is empty. If used properly, this Allocator can greatly improve the performance of specific algorithms. diff --git a/src/NCollection/NCollection_IncAllocator.hxx b/src/NCollection/NCollection_IncAllocator.hxx index 08e4219f0b..7dfe560af5 100644 --- a/src/NCollection/NCollection_IncAllocator.hxx +++ b/src/NCollection/NCollection_IncAllocator.hxx @@ -33,7 +33,12 @@ class Standard_Mutex; * type "aligned_t". To modify the size of memory blocks requested from the * OS, use the parameter of the constructor (measured in bytes); if this * parameter is smaller than 25 bytes on 32bit or 49 bytes on 64bit, the - * block size will be the default 24 kbytes + * block size will be the default 12 kbytes. + * + * It is not recommended to use memory blocks larger than 16KB on Windows + * platform for the repeated operations because Low Fragmentation Heap is + * not going to be used for these allocations which may lead to memory + * fragmentation and the general performance slow down. * * Note that this allocator is most suitable for single-threaded algorithms * (consider creating dedicated allocators per working thread), @@ -50,6 +55,12 @@ class NCollection_IncAllocator : public NCollection_BaseAllocator //! Constructor. //! Note that this constructor does NOT setup mutex for using allocator concurrently from different threads, //! see SetThreadSafe() method. + //! + //! The default size of the memory blocks is 12KB. + //! It is not recommended to use memory blocks larger than 16KB on Windows + //! platform for the repeated operations (and thus multiple allocations) + //! because Low Fragmentation Heap is not going to be used for these allocations, + //! leading to memory fragmentation and eventual performance slow down. Standard_EXPORT NCollection_IncAllocator (size_t theBlockSize = DefaultBlockSize); //! Setup mutex for thread-safe allocations. @@ -83,7 +94,8 @@ class NCollection_IncAllocator : public NCollection_BaseAllocator Standard_EXPORT void Reset (const Standard_Boolean doReleaseMem=Standard_True); - static const size_t DefaultBlockSize = 24600; + //! Default size for the memory blocks - 12KB + static const size_t DefaultBlockSize = 12300; protected: struct IBlock;