Skip to main content

CubicRootResizing

Short summary

This resizing strategy increases an capacity by a geometric factor of the cubic root of 2 (~1.26). After three consecutive growth steps, the capacity approximately doubles, which improves the chance of reusing previously freed memory blocks and helps to reduce heap fragmentation. The strategy is well-suited for memory-constrained or embedded environments where efficient memory reuse is more important than minimizing the number of reallocation operations. For downsizing the capacity is reduced if the new size is less then 25 % of the current capacity.

AccessAbstractFinalExtendsImplements
-NoNoCNM_AbstractObject.ObjectCNM_CollectionInterfaces.IResizingStrategy

UML Diagram

Parameters

none

Properties

className

Type: CNM_AbstractObject.ClassName

This abstract property returns the class name of the concrete object,

initialSize

Type: UDINT

This property returns an inital size for an empty new array.

Methods

getDownscaledCapacity

  • Parameters:
    • requestedSize (UDINT): the new size that is needed
    • currentCapacity (UDINT): the current actual size of the container
  • Return type: BOOL

The method takes the requested size and the current capacity as input and determines the next suitable capacity value based on the implemented resizing strategy.

getUpscaledCapacity

  • Parameters:
    • requestedSize (UDINT): the new size that is needed
    • currentCapacity (UDINT): the current actual size of the container
  • Return type: BOOL

The method takes the requested size and the current capacity as input and determines the next suitable capacity value based on the implemented resizing strategy.

Code

Declaration

{attribute 'enable_dynamic_creation'}
FUNCTION_BLOCK CubicRootResizing EXTENDS CNM_AbstractObject.Object IMPLEMENTS CNM_CollectionInterfaces.IResizingStrategy
VAR CONSTANT
(* cubic root of 2 *)
GROW_FACTOR :REAL := 1.259921049894873165;
END_VAR