SlideShare ist ein Scribd-Unternehmen logo
1 von 26
Downloaden Sie, um offline zu lesen
Specialized Memory Pool for C and
                                C++



                                                      Version 1.6
                                                   June 14, 2006




PathMATE Technical Notes



                                         Pathfinder Solutions LLC
                                     33 Commercial Drive, Suite 2
                                         Foxboro, MA 02035 USA
                                          www.PathfinderMDA.com
                                                   888-662-7284




          ©2008 by Pathfinder Solutions
Table Of Contents
1.   Introduction........................................................................................... 1

2.   Feature Overview................................................................................... 1
     Types of Pools ........................................................................................ 1
       Task-Specific General Purpose Pool........................................................ 1
       Task-Specific Incident Pool ................................................................... 1
       Default Pool........................................................................................ 2
       Fault Handling .................................................................................... 2
     Specification of Pool Block Sizes ................................................................ 2
       General Purpose Task Pool Sizing .......................................................... 2
       Incident Pool Sizing ............................................................................. 3
       Default Pool........................................................................................ 4
     Overall Feature Disabling ......................................................................... 4
     Marking Summary ................................................................................... 4

3.   Feature Implementation ........................................................................ 5
     Mechanism Extensions ............................................................................. 5
     Template Extensions................................................................................ 5
       When to Apply General Purpose Task Pool............................................... 5
     Task-Safety Report.................................................................................. 6
     Usage Statistics Reporting ........................................................................ 6

4.   Feature Design....................................................................................... 6
     Classes .................................................................................................. 7
        MemoryBlock...................................................................................... 7
        PfdAllocationCluster ............................................................................. 7
        PfdBufferManager <<singleton>> ........................................................ 7
        PfdClusterManager .............................................................................. 8
        PfdCriticalSection ................................................................................ 8
        PfdLocalPool ....................................................................................... 8
        PfdPoolBlock....................................................................................... 8
        PfdPoolBlockSpecification ..................................................................... 9
        PfdPoolSpecification............................................................................. 9
        PfdTask ............................................................................................. 9
     Associations ........................................................................................... 9
     Domain Scenarios ..................................................................................10
     Domain Services ....................................................................................21
     PfdAllocationCluster Operations ................................................................21
     PfdBufferManager Operations...................................................................21
     PfdClusterManager Operations .................................................................22




                                                      ii
PfdCriticalSection Operations ...................................................................23
     PfdLocalPool Operations ..........................................................................23
     PfdPoolBlock Operations ..........................................................................23

5.   System Types....................................................................................... 23
     Enumerates...........................................................................................23
     User Defined Types ................................................................................23




                                                    iii
Specialized Memory Pool for C and C++




1. Introduction
This Technical Note describes extensions to PathMATE’s C and C++ Maps to improve
static buffer management. These extensions support task-local memory
management pools. They are based on the buffer manager.
2. Feature Overview
The goals of this feature are to:
    Reduce the run-time overhead associated with dynamic memory allocation,
      which normally goes through the BufferManager, an intertask-safe resource.
      Allow for the specific sizing and allocation of dynamic memory blocks for
       specific classes.
This feature is built upon the base capabilities and characteristics of the
BufferManager mechanism. This is a simple block management mechanism, where
memory blocks of a small number of different sizes are arranged such that a request
for a specific size block will result in the allocation of one of the smallest sized block
available that will satisfy the request. Deallocation marks the originally allocated
block as available again. One consequence of such a simple facility is that there is
no notion of fragmentation – only contiguous blocks are allocated and deallocated, so
no loss of efficiency over time is realized from varying usage and release patterns.
Also, when a larger sized block is used to satisfy a smaller sized request, the entire
block is allocated, so when it is deallocated it is again immediately available for use
up to its complete size.

       Types of Pools
       All dynamically allocated memory elements come from one of three types of
       pools:
      A task-specific general purpose pool
      A task-specific incident pool
      The default pool
       Note - the allocation of class instances from a pre-declared array is currently
       supported via the MaxIndex marking and the InstanceTable mechanism.

       Task-Specific General Purpose Pool
       You may define a memory pool for use within a single task. The pool provides
       task-local allocation and deallocation of memory blocks of a variety of user-
       specified sizes, in support of class instance data. Because it is task-local, the
       task-specific pool avoids the overhead of intertask safety mechanisms.
       Note: If a task-specific pool is defined and a class instance is created for a
       class that did not specify a MaxIndex (and thereby got its own array space),
       the task-specific pool is used.

       Task-Specific Incident Pool
       A task-specific incident pool may be specified. This pool is an array within the
       Task structure that holds pointers to available Incident instances. These are


                                            1
Specialized Memory Pool for C and C++



     used to satisfy any incident allocations within the task. Once allocated, the
     address of the new incident is removed from the Task pool. Any Incidents
     freed within a Task that has an incident pool will go into that task’s pool,
     regardless of where they came from. If a Task with an incident pool runs out
     of Incidents and a request comes in for another, the incident pool is
     replenished from the default pool. If a Task with an incident pool runs fill up
     with available Incidents and another is released, ½ of the available incidents
     in the incident pool are returned to the default pool.
     To support possible incident parameters, when a task-specific incident pool is
     used, a task-specific data container pool is also used. The
     allocation/deallocation mechanics of this pool mirror that of the incident pool.

     Default Pool
     The default pool for dynamic memory allocation is the standard
     BufferManager pool. One instance of the BufferManager is allocated to each
     process in the system. Each instance provides intertask-safe allocation and
     deallocation of memory blocks of a variety of user-customizable sizes. If no
     other pool is specified for a dynamic memory request, or if an Incident is
     destined for the InterTaskIncidentQueue, the BufferManager pool is used.

     Fault Handling
     In the case of running out of memory the default action is to shut down the
     process in which the outage occurred. A new SW Service
     SW:RegisterForErrorGroup(enum fault_type, IncidentHandle handler) will be
     provided to allow for the user configurable handling of the
     SW_FAULT_DEPLETED_MEMORY fault.

     Specification of Pool Block Sizes

     General Purpose Task Pool Sizing
     Task-specific pools are allocated by specifying the “TaskPool-<process
     label>-<task name>” marking. The designer should identify the specific
     sizes of the dynamic elements within their task, and specify block sizes and
     counts appropriately. For example consider a scenario within the
     Robochef.FoodPrep domain where many recipes can be loaded and unloaded.
     Let's say the base RecipeStepSpec class instance overhead is 40 bytes, and a
     maximum of 900 instance of this class are expected. Assume it is allocated
     to its own domain and this specifies a domain-specific pool. One way to
     allocate space for those events is to specify 900 blocks of 40 bytes. A partial
     specification of this would be:
     System,Robochef,TaskPool-MAIN-SYS_TASK_ID_FP,... 900|40; ...

     The sample specification below creates task-specific pools for the tasks
     SYS_TASK_ID_MAIN and SYS_TASK_ID_AUX. Each pool contains 1024 blocks
     in each of three block sizes:
     System,CarShuffle,TaskPool-MAIN-
     SYS_TASK_ID_MAIN,1024|16;1024|48;1024`|196
     System,CarShuffle,TaskPool-MAIN-SYS_TASK_ID_AUX,1024|88;1024|148;1024|306




                                         2
Specialized Memory Pool for C and C++



      Optionally you may specify the reload and unload thresholds for each block
      size in the pool. When the number of blocks in the pool falls below the reload
      threshold, the pool will try to lock the buffer manager. If the buffer manager
      can't be locked, the pool will allocate the block. If the buffer manager can be
      locked, it will replenish the pool and then allocate the block. If the pool is
      empty, it will wait to obtain a lock on the buffer manager.
       When the number of free spots in the pool falls below the unload threshold,
      the pool will try to lock the buffer manager. If the buffer manager can't be
      locked, the pool will deallocate the block. If the buffer manager can be
      locked, the pool will release memory to the buffer manager and deallocate the
      block. If the pool has no free spots, the pool will wait to obtain a lock on the
      buffer manager and release memory back to the buffer manager.
      The default reload and unload thresholds are 5 or one less than the maximum
      count of items in the pool if the pools contains less than 5 items.
      Specify the reload and unload thresholds as follows:
System,CarShuffle,TaskPool-MAIN-SYS_TASK_ID_MAIN,1024|16|2|4;1024|48;1024|196
System,CarShuffle,TaskPool-MAIN-SYS_TASK_ID_AUX,1024|88;1024|148;1024|306|20

      In the example above, the main task pool of size 16 has a reload threshold of
      2 and an unload threshold of 4. The size 48 and 196 pools use the default
      unload and reload threshold of 5.
      The aux task pool of size 306 has an unload threshold of 20 and a default
      reload threshold of 5. There is no way to specify a default reload threshold
      and a non-default unload threshold.
      This feature is not supported on Windows using Visual C++ 6.0 and on OSE.
      These platforms do not support an unblocked acquisition of a mutex.
      NOTE: Reload and unload thresholds are only supported in C++.

      Incident Pool Sizing
      Task-specific incident pools are allocated by specifying the
      “TaskIncidentPool-<process label>-<task name>” and
      “TaskIncidentParameterPool-<process label>-<task name>” markings.
      The value of these markings is the maximum number of pre-allocated incident
      or parameter blocks to be made available. They should be tuned to support
      the incident and incident parameter needs of your system during high usage
      scenarios. The compiler flag PATH_MEMORY_STATISTICS will turn on
      statistics collection in the BufferManager and the LocalPools. Each of these
      classes has a reportStatistics operation that can be called to print out
      statistics on memory usage which can help the designer tune the memory
      pool sizes.
      The sample specification below creates task-specific incident and parameter
      pools for the tasks SYS_TASK_ID_MAIN in the MON process, and
      SYS_TASK_ID_AUX in the PIO. Each task has 100 incidents and 50
      parameters:
      System,CarShuffle,TaskIncidentPool-MON-SYS_TASK_ID_MAIN,100
      System,CarShuffle,TaskIncidentParameterPool-MON-SYS_TASK_ID_MAIN,50
      System,CarShuffle,TaskIncidentPool-PIO-SYS_TASK_ID_AUX,100


                                         3
Specialized Memory Pool for C and C++



     System,CarShuffle,TaskIncidentParameterPool-PIO-SYS_TASK_ID_AUX,50

     Default Pool
     Block sizes for the standard BufferManager pool can now be specified by the
     system marking “DefaultPoolSizes.” This property takes a list of sizes
     (numeric literals or symbolic constants) in increasing order. If
     “DefaultPoolSizes” is not specified the standard BufferManager pool will
     retain the default pool configuration as specified in the BufferManager
     mechanism module. The sample specification below explicitly calls out block
     sizes matching the delivered BufferManager implementation:
 System,CarShuffle,DefaultPoolSizes,2048|32;1638|40;1365|48;1024|64;
 512|128;128|512;32|2048;1|0xFFFF

     Overall Feature Disabling
     All task-local pools (general, incident and parameter) are gated with the
     PATH_USE_LOCAL_POOLS compiler flag. This flag is set by default in
     generated project files and makefiles. Setting the system marking
     DisableLocalPools to "TRUE" prior to generating project files and makefiles will
     cause the PATH_USE_LOCAL_POOLS compiler flag not to be set, disabling all
     task-local pools.

     Marking Summary
     The following markings control this feature:

Model
Element      Name                                        Value
System       DefaultPoolSizes                            <count>|<size>;<count>|<size>…
System       DisableLocalPools                           TRUE, FALSE (FALSE)
System       TaskPool-<process id>-<task id>             <count>|<size>;<count>|<size>…
             TaskIncidentPool-<process id>-<task
System       id>                                         <size>
             TaskIncidentParameterPool-<process
System       id>-<task id>                               <size>

     Where:
            <count> and <size> are integer literals or symbolic constants,
            <process id>-<task id> specify a valid process label and task id (from
     domain marking)
     In addition to marking-based controls, all BufferManager capabilities,
     excluding specialized pools, can be replaced by native malloc and free calls by
     setting the compile switch PATH_NO_BUFFER_MANAGER.




                                        4
Specialized Memory Pool for C and C++




3. Feature Implementation
      Mechanism Extensions
      Extensions to the C-Maps base mechanisms and system files take the existing
      SW_BufferManager mechanism and generalize it. These extensions allow for
      multiple instances, either task-local or intertask-safe, and configurable block
      sizes. To specify the block size for the default pool, the main() function calls a
      generated pool allocation and configuration function.
      The SW_Task structure adds the data member memoryPool to allow for a
      task-specific pool. If specified, this task-specific pool would be used in class
      instance and link structure allocations instead of the default pool.
      The SW_Task structure adds the data members incidentPool and
      parameterPool to allow for a task-specific incident pools. If specified, the
      task-specific pool would be used in SW_Incident_new,
      SW_Incident_deallocate, SW_DataContainer_new and
      SW_DataContainer_deallocate instead of the buffer manager.
      To support the use of class-specific pools, the functions
      SW_BufferManager_allocBlockForPool and
      SW_BufferManager_freeBlockForPool are added.
      To streamline operations on sets of allocations and deallocations (supporting
      task-specific incident and parameter pools) by reducing the overhead of
      entering and leaving the SW_BufferManager critical section, a transactional-
      style interface will be added to the SW_BufferManager.
      SW_BufferManager_startTransaction, SW_BufferManager_endTransaction,
      SW_BufferManager_fastAlloc and SW_BufferManager_fastFree functions will
      be added

      Template Extensions
      Extensions to the C-Maps code generation templates are applied to ensure the
      proper memory mechanisms are used in accord with the marking values.
      A pool allocation and configuration function is generated to specify the block
      sizes for the default pool. This function is called from the main() function.
      The generated function System_Run() is modified to create, configure, and
      delete task-specific pools as specified by markings.

      When to Apply General Purpose Task Pool
      Template modifications are required to ensure that only truly local requests
      are mode of the general purpose task pool. In order for a class to use this
      pool the following conditions must be met:
  -   The class is in a specific fixed task, and not SYS_TASK_ANY.
  -   The class is not statically allocated, and does not have a MaxIndex value
      specified indicating direct array storage.
  -   The class is allocated to a task with a general purpose pool defined.




                                           5
Specialized Memory Pool for C and C++



  -   All actions where the class is CREATEd and DELETEd are allocated to the
      same fixed task.

      Task-Safety Report
      If only domain multi-task is implemented, then there will be no circumstances
      where the use of task-specific pools could result in an unsafe intertask
      memory access. However with domain operation multi-task or class multi-
      task support, it may be possible to specify that a single domain can run in
      multiple tasks. In this case, a set of templates will be run as part of code
      generation pre-processing to look for uses of task-specific pools that may
      incorrectly span task boundaries.
      For example, assume the Carshuffle VehicleHousing domain has some domain
      operations that run in SYS_TASK_ID_MAIN , and some domain operations
      that run in SYS_TASK_ID_AUX. If the class VH.Car does not specify a
      MaxIndex and is not statically initialized, task-specific pools are specified, and
      Car instances are CREATEd in the task SYS_TASK_ID_MAIN and DELETEd in
      the task SYS_TASK_ID_AUX, this will be highlighted as a run-time issue via a
      transformation Engine LOGERROR message.
      Allocating memory in one task and then deallocating it in another task is
      problematic if the pool specifications do not support the exact same size
      blocks. For example, if task T1 supports blocks of 16, 32 and 64 bytes and
      T2 supports blocks of 32 and 64 bytes, a problem occurs if a block of size 16
      or less were allocated in T1 and deallocated in T2.
      For example, T1 receives a request to allocate a block of size 8. T1 chooses a
      block size of 16 because it is the closest block size to 8. When the block is
      deallocated in T2, the pool block chooses the first pool with size >= to 8. For
      T2, this is 32. The block, which is actually size 16, is now in a pool of size 32
      blocks. If the size 16 block is allocated as if it is 32, memory corruption will
      occur as 16 bytes of the adjacent block in the buffer manager will be
      overwritten.

      Usage Statistics Reporting
      As a tool to designers to aid in the proper allocation of pools, simple statistics
      will be kept throughout each execution of the system, and reported upon
      system shutdown. For the default process pool and for each task-specific
      general purpose pool, the maximum number of blocks on a per-cluster (block-
      size) basis will be kept – a “high water” mark will be reported. In addition,
      the current number of blocks (per cluster) still in use at shutdown time will be
      reported.
      For the task-specific incident pool, the total number of incidents allocated and
      released will be reported per-task. (It is thought that deficit trends – where a
      large imbalance exists in this area might be useful information).
      All of the above statistic collection and report code is activated by the
      PATH_MEMORY_STATISTICS compile flag.


4. Feature Design

                                          6
Specialized Memory Pool for C and C++




                                                                                         PfdPoolSpecification
      PfdPoolBlockSpecification         1             A1 2                   1..n
                                                                                     size : Integer
     count : Intege r
                                                   +pool_specification               count : Integer
                                                                                     reloadThreshold : Integer
              1..*
                                                                                     unloadThreshold : Integer
               +cluster_specification
       A15
              1
              <<singleton>>
         PfdBufferManager
    gHandle : PfdBufferManager
    emergencyReserve : Handle

    startTransaction()
    endTransaction()                                                    PfdClusterManager           +manager              A1 8
    fastAlloc()                                A1 3                     size Index : Integer
    fastFree()                                                                                      1
    maxAllocSize()                      1                    0..*       nextFre eBlo ck()
    whichBlockIndex()                       +cluster_manager            allocateCluster()
    reportError()
                                                                             1
    isAllocated()                                               1                                                          0.. *
    allocBlock()
    freeBlock()                                                                                            PfdAllocationCluster
                                                                            A14                         clusterIndex : Integer
                          0..*                                                                          cluster : Handle
                                                             A17                    +top_cluster
                     A1                                                                                 freeBlockCount : Integer
                                                                                            0..1                                        1
      +crit_section       0..1                                                                          nextFreeBlock()
                                                                    +first_cluster_with_free            freeBlock()
             PfdCriticalSection
                                                                                            0..1                  0..1      0..1
             inUse : Mutex
                                                                                                        0..1
                                                                                                                                       A1 6
                                                                        +cluster_allocated_from
             Enter()
                                                                                                                            +next_cluster
             Leave()
             Try()                                                                            A21           A22

                                                                                                                  +next_free_item
                                                                                                        0 ..*     0..1
                                                                                             MemoryBlock




                                 Memory Management Software Mechanisms Class
                                                 Diagram

      Classes

      MemoryBlock
      (U) A block of free memory residing in a local pool or buffer manager.

      PfdAllocationCluster
      (U) A block of memory divided up and allocated out in equal sized blocks.
          cluster (Handle): (U) Block of space managed by the cluster. This
               space is divided up into blocks of the appropriate size and allocated.
          clusterIndex (Integer): (U) The index of the cluster into the list of
               clusters held by the cluster manager.
          freeBlockCount (Integer): (U) The number of free blocks left within this
               cluster.

      PfdBufferManager <<singleton>>
      (U) Allocates and frees dynamic memory blocks efficiently by using a limited
      set of block sizes. The buffer manager is a singleton instance that can be
      accessed by any of the tasks in the program. The buffer manager is
      protected by a mutex so it can be accessed by multiple tasks.


                                                                    7
Specialized Memory Pool for C and C++



     (U) The population of block sizes can be customized by specifying design
     markings.
         emergencyReserve (Handle): (U) Reserved memory to be released if
             memory runs out. Releasing the reserved memory will allow the
             system to terminate gracefully.
         gHandle (PfdBufferManager): (U) The singleton instance of the buffer
             manager.

     PfdClusterManager
     (U) Tracks all of the clusters holding memory blocks of the same size. The
     cluster manager creates clusters at initialization time and allocates new
     clusters as the existing clusters run out of memory blocks.
          sizeIndex (Integer): (U) The size of the block held by this cluster.

     PfdCriticalSection
     (U) A synchronization mechanism to support concurrent access to a shared
     resource.
         inUse (Mutex): (U) The mutex or critical section providing locking to the
             client tasks. The implementation is platform specific.

     PfdLocalPool
     (U) A pool of memory blocks of itemSize allocated from the buffer manager.
     The memory pool avoids the overhead of acquiring the critical section for the
     singleton buffer manager each time an allocation is done.
     (U) At startup, the pool acquires the buffer manager critical section and loads
     the pool. When the number of free blocks drops below the reloadThreshold,
     the pool attempts to acquire the buffer manager critical section and reload
     the pool.
     (U) If the number of empty slots in the pool falls below the unloadThreshold,
     the pool attempts to acquire the buffer manager critical section and returns
     memory to the buffer manager.
         itemSize (Integer): (U) The size of the memory blocks held in the pool
              in bytes.
         maxCount (Integer): (U) The maximum number of memory blocks that
              can be stored in the pool.
         nextAvailable (Integer): (U) The index of the next free block or -1 if no
              free blocks are available.
         reloadThreshold (Integer): (U) Start trying to acquire the lock on the
              buffer manger to reload the pool when the number of free blocks falls
              below this number.
         unloadThreshold (Integer): (U) Start trying to acquire the buffer
              manager lock to unload the pool when the number of free spaces
              falls below this number.

     PfdPoolBlock
     (U) A set of local memory pools of different sizes used exclusively by a
     particular task.
         poolCount (Integer): (U) The number of local pools in this block




                                        8
Specialized Memory Pool for C and C++



     PfdPoolBlockSpecification
     (U) Defines the parameters for a set of memory pools.
         count (Integer): (U) The number of pools of different sizes available.

     PfdPoolSpecification
     (U) Defines the parameters for the memory blocks held by a memory pool.
         count (Integer): (U) The number of blocks of memory in the pool.
         reloadThreshold (Integer): (U) When the number of free blocks in the
              pool falls below this threshold, start attempting to acquire the lock on
              the buffer manager.
         size (Integer): (U) The size of each block of memory in the pool.
         unloadThreshold (Integer): (U) When the number of empty spots in
              the pool falls below this threshold, start attempting to acquire the
              lock on the buffer manager.

     PfdTask
     (U) A thread of control for dispatching events to state models and executing
     actions.

     Associations
     A1 :
         PfdCriticalSection crit_section (0..1)  A1  (*) PfdBufferManager
         description: (U) The critical section that protects the buffer manager as
             memory is allocated by multiple threads.
         SortOrder: FIFO
     A11 :
         PfdLocalPool pool_block (1..*)  A11  (1) PfdPoolBlock
         description: (U) A set of memory pools holding items of different sizes.
         SortOrder: FIFO
     A12 :
         PfdPoolSpecification pool_specification (1..*)  A12  (1)
             PfdPoolBlockSpecification
         description: (U) Defines all the memory pool sizes supported by the pool
             block. PoolSpecifications are order by ascending size across this
             association
         SortOrder: ascending
     A13 :
         PfdClusterManager cluster_manager (*)  A13  (1) PfdBufferManager
         description: (U) The cluster managers that perform allocations on the
             different block sizes.
         SortOrder: FIFO
     A14 :
         PfdAllocationCluster top_cluster (0..1)  A14  (1) PfdClusterManager
         description: (U) The first cluster of the specified size.
         SortOrder: FIFO
     A15 :
         PfdPoolBlockSpecification cluster_specification (1..*)  A15  (1)
             PfdBufferManager
         description: (U) Defines the set of memory block sizes supported by the
             buffer manager.


                                         9
Specialized Memory Pool for C and C++



        SortOrder: FIFO
     A16 :
        PfdAllocationCluster next_cluster (0..1)  A16  (1) PfdAllocationCluster
        description: (U) The next cluster allocating blocks of the same size.
        SortOrder: FIFO
     A17 :
        PfdAllocationCluster first_cluster_with_free (0..1)  A17  (1)
            PfdClusterManager
        description: (U) First cluster managed by the manager that may contain a
            free block.
        SortOrder: FIFO
     A18 :
        PfdClusterManager manager (1)  A18  (*) PfdAllocationCluster
        description: (U) Defines the parent manager for this cluster.
        SortOrder: FIFO
     A19 :
        MemoryBlock item_pool (*)  A19  (1) PfdLocalPool
        description: (U) The set of free blocks in the local pool. This association
            is implemented as an array of size maxCount. The array holds the
            set of available blocks. Blocks may be freed to an empty spot in the
            array. The nextAvailable attribute keeps track of the first memory
            block stored in the array.
        SortOrder: FIFO
     A20 :
        PfdPoolBlock general_pool_block (0..1)  A20  (1) PfdTask
        description: (U) The general purpose local memory pool for this task.
            When linked, use this pool when allocating memory from this task.
        SortOrder: FIFO
     A21 :
        PfdAllocationCluster cluster_allocated_from (0..1)  A21  (*)
            MemoryBlock
        description: (U) A memory block when it is allocated points back to its
            cluster. When it is deallocated, the pointer is used to determine its
            owning cluster.
        SortOrder: FIFO
     A22 :
        MemoryBlock next_free_item (0..1)  A22  (0..1) PfdAllocationCluster
        description: (U) The free memory block in this cluster with the lowest
            address. The next memory block to be allocated.
        SortOrder: FIFO




     Domain Scenarios




                                        10
Specialized Memory Pool for C and C++




    UNCLASSIFIED                       Allocate from Buffer Manager - New Cluster Required


                          : Pfd BufferMana ger                     :                         exi sti ng :
                                                          PfdCluste rManager            PfdAllocationCluster
       : clie nt
             1: allocBlock(Integer)
                                                             Find the cluster manager
                         2: startTransaction(Boolean)        for requested size.

                         3: whichBlockIndex(Integer)                           Try existing clusters to find
                                                                               one with a free block.
                                         4: nextFreeBlock( )

                                                                         5: nextFreeBlock( )

                                                                           6: Return null

                                                 7: allocateCluster(Ref<PfdAllocationCluster>)

                              can't find a free                                    8: <<create>>                         new :
                              block. Allocate a
                                                                                                                  PfdAllocationCluster
                              new cluster.

                                                                                      9: nextFreeBlock( )


                                                                                                          Find a new free block to
                                                                                                          prepare for the next
                                                                                                          allocation.

                                                                   10: isAllocated(Handle)

                                                                                                               Mark allocated block
                                                                                                               with owning cluster.
                                                                                   11: Return Block Handle

                                      12: Return Block Handle

                             13: endTransaction( )



          14: Return Block Handle



    Description:
    Allocate a block of memory from the buffer manager. For this
    nominal flow, a block of memory is successfully allocated from a
    newly allocated cluster.

    Preconditions:                                                                                        UNCLASSIF IED
    1. Buffer manager is initialized.
    2. Size of memory block requested is less than the maximum size
    supported by buffer manager configuration.
    3. Operating system has sufficient free heap memory to allocate a
    new cluster.
    4. Existing clusters of the size requested do not have any free
    blocks.

    Postconditions:
    1. Buffer manager located and returned a handle to memory block
    of the appropriate size.




   Domain Scenario - Allocate from Buffer Manager - New Cluster Required




                                                                   11
Specialized Memory Pool for C and C++




    UNCLASSIFIED                       Allocate from Buffer Manager - Out of Memory


                          : Pfd BufferMa nager                     :                         existing :
                                                          PfdClusterManager             PfdAlloca tionCluster
      : client
           1: allocBlock(Integer)
                                                             Find the cluster manager
                          2: startTransaction(Boolean)       for requested size.

                          3: whichBlockIndex(Integer)                         Try existing clusters to find
                                                                              one with a free block.
                                         4: nextFreeBlock( )                                         No free blocks found in
                                                                                                     existing clusters.
                                                                         5: nextFreeBlock( )         Allocatio n of a new cluster
                                                                                                     fails.
                                                 6: allocateCluster(Ref<PfdAllocationCluster>)


                                                                                  7: <<create>>                 new :
                                                                                                         PfdAlloca ti onCluster
                                    8: reportError(sw_predefined_error_group_e group, sw_predefined_error_code_e)

                                                          handlers for this error code are
                             9: endTransaction( )         called by PfdProcess.



                 10: Return NULL



   Description:
   Allocate a block of memory from the buffer manager. For this
   exceptional flow, a block of memory is can't be allocated because
   there are no free blocks and a new cluster can't be allocated
   because the operating system runs out of memory.

   Preconditions:
   1. Buffer manager is initialized.
   2. Size of memory block requested is less than the maximum size
   supported by buffer manager configuration.
   3. Operating system does not have sufficient free heap memory to
   allocate a new cluster if necessary.

   Postconditions:
   1. Out of memory error is reported to software mechanisms error
   handler.
   2. Registered error handlers are called.
                                                                                                          UNCLASSIFIED




         Domain Scenario - Allocate from Buffer Manager - Out of memory




                                                                   12
Specialized Memory Pool for C and C++




    UNCLASSIFIED                       Allocate from Buffer Manager - Nominal


                         : PfdBufferManager                      :                               :
                                                        PfdClusterManager               PfdAllocationCluster
      : client
           1: allocBlock(Integer)
                                                           Fi nd the cluster manager
                        2: startTransaction(Boolean)       for re queste d si ze.

                        3: whichBlockIndex(Integer)                          Try exi sti ng cluste rs to find
                                                                             one wi th a free b lock.
                                         4: nextFreeBlock( )
                                                                                                         Find a new fre e block to
                                                                        5: nextFreeBlock( )              prepare for the next
                                                                                                         allocation.

                                                       6: isAllocated(Handle)

                                                                                                       Mark allocated block
                                                                                                       with owning cluster.


                                                                       7: Return Block Handle

                                       8: Return Block Handle


                            9: endTransaction( )

         10: Return Block Handle



    Descri ption:
    Allocate a block of me mory from the buffer manager. Fo r this
    nomina l flow, a block of memo ry is successfully allocated from
    existing cluster.

    Precond itions:
    1. Buffer manager i s i nitialize d.
    2. Size of memory block re queste d is less than the maximum
    size suppo rted by buffer mana ger configuration.
    3. Exi sting clusters of the si ze reque sted hold fre e blocks.

    Po stcondi ti ons:
    1. Buffer manager located a nd returned a handle to memory
    block of the appropriate size.
                                                                                                          UNCLASSIFIED




                        Domain Scenario - Allocate from Buffer Manager




                                                                 13
Specialized Memory Pool for C and C++




     UNCLASSIFIED                      Allocate from Lo cal Pool - Out of Memory

                              : PfdPoolBlock                 : Pfd LocalP ool                      :
                                                                                           PfdBufferManager
       : client
            1: allocateItem(Integer)

                      Locate local pool of
                      size block requested


                                             2: allocateItem( )

                                                                       3: startTransaction(Boolean)
                                                                                                       See Buffer Manager
                                                                           4: fastAlloc(Integer)
                               Attempt to reload                                                       Allocation Out of
                               pool fails.                                   5: Return NULL            Memory Scenarios
                                                                                                       for more details.
                                                                           6: endTransaction( )


                                             7: Return NULL

                  8: Return NULL




   Description:
   Allocate a block of memory from a local pool. For this exceptional
   flow, the pool is empty and there is insufficient memory to reload the
   local pool. The allocation fails.

   Preconditions:
   1. Buffer manager is initialized.
   2. Local pools are initialized.
   3. Size of memory block requested is less than the maximum size
   supported by local pool configuration.
   4. Local pool of correct size is empty.
   5. Buffer manager can't allocate enough memory to reload the local
   pool.

   Postconditions:
   1. Local pool located and null handle is returned.

                                                                                                      UNCLASSIFIED



                  Domain Scenario - Allocate from Local Pool - Out of Memory




                                                                  14
Specialized Memory Pool for C and C++




    UNCLASSIFIED                       Allocate from Local Pool - Reload Required

                             : PfdPoolBlock                 : PfdLocalPool                        :
                                                                                          PfdBufferManager
      : client
           1: allocateItem(Integer)

                    Locate local pool of
                    size block requested


                                            2: allocateItem( )

                                                                      3: startTransaction(Bo olean)
                                                                                                      See Buffer Manager
                             Allocate enough                              4: fastAlloc(Integer)
                                                                                                      Allocation
                             blocks to fill half                                                      Scenarios for more
                                                                        5: Return Memory Block
                             the pool.                                                                details.
                                                                          6: endTransaction( )

                                                         Update next available
                                                         block to prepare for
                                                         next allocation.
                                       7: Return Memory Block

          8: Return Memory Block


  Description:
  Allocate a block of memory from a local pool. For this nominal flow,
  the pool is empty and is successfully reloaded before allocating a
  block.

  Preconditions:
  1. Buffer manager is initialized.
  2. Local pools are initialized.
  3. Size of memory block requested is less than the maximum size
  supported by local pool configuration.
  4. Local pool of correct size is empty.
  5. Buffer manager contains sufficient free memory to support
  reloading the pool.

  Postconditions:
  1. Local pool located and returned a handle to memory block of the
  appropriate size.
                                                                                    UNCLASSIFIED




             Domain Scenario - Allocate from Local Pool - Reload required




                                                                 15
Specialized Memory Pool for C and C++




     U NC LASSIFIED                     Allo cate from Lo cal Po ol - N omina l

                              : PfdPoolBlock                 : PfdLocalPool


       : client
            1: allocateItem(Intege r)

                     Locate local pool of
                     size block requested


                                            2: allocateItem( )

                                                     Update next available
                                                     block to prepare for
                                                     next allocation.

                                        3: Return Memory Block

           4: Return Memory Block



   Description:
   Allocate a block of memory from a local pool. For this nominal flow,
   a block of memory is available in the local pool and no reload is
   necessary.

   Preconditions:
   1. Buffer manager is initialized.
   2. Local pools are initialized.
   3. Size of memory block requested is less than the maximum size
   supported by local pool configuration.
   4. Local pool contains a block of the correct size.

   Postconditions:
   1. Local pool located and returned a handle to memory block of the
   appropriate size.
                                                                                  UNCLASSIFIED



                          Domain Scenario - Allocate from Local Pool




                                                        16
Specialized Memory Pool for C and C++




     UNCLASSIF IED                 Deallocate to Buffer Manager - Nominal

                            :                     : Pfd Allocati onCluste r
                    PfdBufferManager
      : client
         1: freeBlock(Handle)

                   2: startTransaction(Boolean)


              Use the bytes before the
              memory block handle to find
              the cluster owning the block.

                                  3: freeBlock(Handle)

                       4: endTransaction( )



   Description:
   Deallocate a block of memory and release it to the buffer
   manager. For this nominal flow, a block of memory is
   successfully deallocated.

   Preconditions:
   1. Buffer manager is initialized.
   2. Block being deallocated was allocated from buffer manager.
   3. Block being deallocated is non-NULL.

   Postconditions:
   1. Memory block returned to free storage and is ready to be                U NC LAS SIFIE D
   allocated again.




                     Domain Scenario - Deallocate to Buffer Manager




                                                         17
Specialized Memory Pool for C and C++




      UNCLASSIFIED                     Deallocate to Local Pool - Unload Required

                                 :                   : PfdLocalPool                   :
                           PfdPo olBlock                                      PfdBufferManager

         : client

    1: dea llocateItem(Integer, Handle )

                                 2: dea lloca teItem(Handle )

                                                           3: startTransaction(Boolean)          Return half the
                                                                                                 blocks in the pool
                                                                4: fastFree(Handle)              back to the buffer
                                                                5: endTransaction( )             manager.
                               Set next available
                               and prepare for next
                               allocation.



   Descri pti on:
   Deallocate a block of me mory a nd relea se i t to the loca l p ool. For
   this nomi nal flow, the local pool doe s not have any empty slo ts and
   the local pool must return memo ry back to the buffer manager.

   Precondi ti ons:
   1. Buffer ma nager is initialized.
   2. Block being deallocated was allocated from local pool or b uffer
   manager.
   3. Block being deallocated is non-NULL.
   4. Loca l p ool no fre e slots in it to store the ne wly freed block.

   Po stcondi ti ons:
   1. Memory block re turned to free storage and i s ready to be
   allocated a gain.
                                                                                          U NC LAS SIFIE D



              Domain Scenario - Deallocate to Local Pool - Unload required




                                                             18
Specialized Memory Pool for C and C++




      UNCLASSIFIED                     Deallocate to Local Pool - Nominal

                                :                    : PfdLocalPool
                           PfdPoolBlock

         : client

     1: deallocateItem(Integer, Handle)

                                 2: deallocateItem(Handle)

                                   Set next available
                                   and prepare for next
                                   allocation.


   Description:
   Deallocate a block of memory and release it to the local pool. For
   this nominal flow, the local pool has empty slots in it and no unload
   is required.

   Preconditions:
   1. Buffer manager is initialized.
   2. Block being deallocated was allocated from local pool or buffer
   manager.
   3. Block being deallocated is non-NULL.
   4. Local pool has at least one free slot in it to store the newly freed
   block.

   Postconditions:
                                                                             UNCLASSIFIED
   1. Memory block returned to free storage and is ready to be
   allocated again.



                           Domain Scenario - Deallocate to Local Pool




                                                         19
Specialized Memory Pool for C and C++




   UNCLASSIFIED                                    Initia liz e B uffer Manag er - Out o f Me mo ry

                        :                  create one clus ter manag er fo r
               PfdB ufferManag er          each memo ry block size i n poo l
                                           speci fi cation.
                               1: <<create>>                  :
                                                     PfdClusterManager

                                            2: allocateCluster(Ref<PfdAllocationCluster>)


                                                                    3: <<create>>                :
                                                                                        PfdAllocationCluster

                 4: reportE rror(sw_prede fi ned_erro r_g roup _e g roup , sw_predefi ned_erro r_co de_e)


             handlers for this error code
             are called by PfdProcess


  Description:
  The operating system runs out of memory while the buffer
  manager is initializing its clusters. An out of memory error is
  reported.

  Preconditions:
  1. System is initializing.
  2. Operating system has insufficient memory to allocate all the
  clusters.

  Postconditions:
  1. Out of memory error is reported to software mechanisms
  error handler.
  2. Registered error handlers are called.
                                                                                    UNCLASSIFIED



           Domain Scenario - Initialize Buffer Manager - Out of Memory




                                                       20
Specialized Memory Pool for C and C++




                                                      Initia lize B uffer Manage r
     UNC LAS SIFIE D

                         :                   create one cluster manager for
                 PfdBufferManager            each memory block size in pool
                                             specification.
                                 1: <<create>>                :
                                                     PfdClusterManage r
                                              2: allocateCluster(Ref<PfdAllocationCluster>)


                                                                       3: <<create>>            :
                                                                                       PfdAllocationCluster

                                                                                              allocate a block of memory
                                                                                              from the operating system
                                                                                              of size = block size * block
                                                                                              count

   D escription:                                                                              set up next free item and
   The buffer manage r initializes its clusters. F or this nominal flow,                      free block count
   clusters are successfully allocate d fro m the operating syste m
   m emo ry manager.

   Precond itions:
   1. S ystem is initia lizing.
   2. Operating system has suffi cient memory to allocate all the
   clusters.

   Po stconditions:                                                                                 UNCLASSIFIED
   1. Clusters are p opulated according to memory pool
   specifications.
   2. B uffer m anager is read y to allocate new memory blocks.



                             Domain Scenario - Initialize Buffer Manager

Domain Services

PfdAllocationCluster Operations
   PfdAllocationCluster:freeBlock (instance-based): (U) Return a memory block back to the free store
        so it can be allocated again.
      in:       item_to_free (Handle): (U) The block to free.

   PfdAllocationCluster:nextFreeBlock (instance-based): (U) Returns the next free block in the
       cluster. Returns 0 if none are available.
      returns: (Handle)


PfdBufferManager Operations
   PfdBufferManager:allocBlock (instance-based): (U) Allocate a block of memory of at least size and
        return a handle to it.
      returns: (Handle)
      in:      size (Integer): (U) The minimum size of the memory block to allocate.

   PfdBufferManager:endTransaction (object-based): (U) Unlock the mutex for the buffer manager.

   PfdBufferManager:fastAlloc (object-based): (U) Allocate without locking the mutex. The client
        must call startTransaction before calling this member function.
      returns: (Handle)
      in:      size (Integer): (U) The size of the memory block to be allocated.


                                                                  21
Specialized Memory Pool for C and C++




  PfdBufferManager:fastFree (object-based): (U) Free without locking the mutex. The client must
       call startTransaction before calling this member function.
     in:       block_to_free (Handle): (U) The handle to the block that will be returned to available
               free memory.

  PfdBufferManager:freeBlock (instance-based): (U) Put a block to the free store. The block is ready
       to be allocated again.
     in:       block (Handle): (U) A handle to the block to be freed. Ignore NULL handles.

  PfdBufferManager:isAllocated (object-based): (U) Return TRUE if the block has already been
       allocated. Return FALSE if the block is free.
     returns: (Boolean)
     in:      block_handle (Handle): (U) Check this memory block to see if it is allocated or free.

  PfdBufferManager:maxAllocSize (object-based): (U) Return the maximum size block that can be
      allocated from the buffer manager.
     returns: (Integer)

  PfdBufferManager:reportError (instance-based): (U) Report an memory error detected during
       allocation or deallocation.
     in:      error_group (sw_predefined_error_group_e group): (U) Report an error belonging to
              this group.
     in:      error_code (sw_predefined_error_code_e): (U) Report an error with this code.

  PfdBufferManager:startTransaction (object-based): (U) Obtain the mutex required for accessing
       the buffer manager. Return TRUE if the lock could be obtained. Return FALSE, if
       wait_for_critical was FALSE and the buffer manager lock could not be obtained without
       waiting.
     returns: (Boolean)
     in:      wait_for_critical (Boolean): (U) If TRUE, block while waiting for the buffer manager
              mutex. If FALSE, only lock the mutex if it can acquired without waiting.

  PfdBufferManager:whichBlockIndex (object-based): (U) Return the index of the cluster used to
       allocate a block of the requested size.
     returns: (Integer)
     in:      request_size (Integer): (U) The size of the block requested.


PfdClusterManager Operations
  PfdClusterManager:allocateCluster (instance-based): (U) Allocate a new cluster for this manager.
       Return TRUE if successful.
     returns: (Boolean)
     in:      previous_cluster (Ref<PfdAllocationCluster>): (U) The previous cluster in the chain of
              clusters.

  PfdClusterManager:nextFreeBlock (instance-based): (U) Return a free block from an allocation
      cluster. Return 0 if all clusters are used and no new clusters can be allocated.
     returns: (Handle)




                                                22
Specialized Memory Pool for C and C++



PfdCriticalSection Operations
   PfdCriticalSection:Enter (instance-based): (U) Lock the critical section. Suspend the task and wait
       if the critical section is locked by another task.

   PfdCriticalSection:Leave (instance-based): (U) Unlock the critical section so that other tasks may
       access the shared resource.

   PfdCriticalSection:Try (instance-based): (U) Try to lock the critical section. Don't wait if the
       critical section is locked by another task. Return TRUE if the critical section was sucessfully
       locked. Return FALSE if the critical section ws not successfully locked. To acquire the lock, the
       client must call Enter to wait for the lock to become availble or poll using Try.
      returns: (Boolean)


PfdLocalPool Operations
   PfdLocalPool:allocateItem (instance-based): (U) Allocated a block of memory from the pool.
       Return a pointer to the block or 0 if the block can't be allocated.
      returns: (Handle)

   PfdLocalPool:deallocateItem (instance-based): (U) Free a block of memory.
      in:    item (Handle): (U) A pointer to the block of memory to free.

   PfdLocalPool:reload (instance-based): (U) Reload the pool with more blocks from the buffer
       manager if it is empty or almost out.

   PfdLocalPool:unload (instance-based): (U) Return some of the empty memory to the buffer manager
       if the pool is completely full or nearly full.


PfdPoolBlock Operations
   PfdPoolBlock:allocateItem (instance-based): (U) Find the correct pool containing the correct
        memory block size. Allocate a block of memory from the pool and return a pointer to the
        memory.
      returns: (Handle)
      in:    size (Integer): (U) The size of the block of memory to allocate.

   PfdPoolBlock:deallocateItem (instance-based): (U) Return a memory block to the pool for its size.
      in:    item_size (Integer): (U) The size of the memory block pointed to by item in bytes.
      in:    item (Handle): (U) A handle to the block of memory to be freed.




5. System Types
Enumerates

User Defined Types
Mutex : base: Integer
PfdBufferManager : base: Integer
sw_predefined_error_code_e : base: Integer
sw_predefined_error_group_e group : base: Integer


                                                 23

Weitere ähnliche Inhalte

Was ist angesagt?

Platform Migration Guide
Platform Migration GuidePlatform Migration Guide
Platform Migration Guide
white paper
 
Automated provisioning using ibm tivoli intelligent orchestrator and enterpri...
Automated provisioning using ibm tivoli intelligent orchestrator and enterpri...Automated provisioning using ibm tivoli intelligent orchestrator and enterpri...
Automated provisioning using ibm tivoli intelligent orchestrator and enterpri...
Banking at Ho Chi Minh city
 
Deployment guide series ibm total storage productivity center for data sg247140
Deployment guide series ibm total storage productivity center for data sg247140Deployment guide series ibm total storage productivity center for data sg247140
Deployment guide series ibm total storage productivity center for data sg247140
Banking at Ho Chi Minh city
 
iPDC User Manual
iPDC User ManualiPDC User Manual
iPDC User Manual
Nitesh Pandit
 
EMC NetWorker Module for Microsoft SQL Server Administrators ...
EMC NetWorker Module for Microsoft SQL Server Administrators ...EMC NetWorker Module for Microsoft SQL Server Administrators ...
EMC NetWorker Module for Microsoft SQL Server Administrators ...
webhostingguy
 
Backing up web sphere application server with tivoli storage management redp0149
Backing up web sphere application server with tivoli storage management redp0149Backing up web sphere application server with tivoli storage management redp0149
Backing up web sphere application server with tivoli storage management redp0149
Banking at Ho Chi Minh city
 
Metatron Technology Consulting 's MySQL to PostgreSQL ...
Metatron Technology Consulting 's MySQL to PostgreSQL ...Metatron Technology Consulting 's MySQL to PostgreSQL ...
Metatron Technology Consulting 's MySQL to PostgreSQL ...
webhostingguy
 
Ibm total storage productivity center for replication on linux sg247411
Ibm total storage productivity center for replication on linux sg247411Ibm total storage productivity center for replication on linux sg247411
Ibm total storage productivity center for replication on linux sg247411
Banking at Ho Chi Minh city
 
Virtual backup strategies_using_storage_snapshots_for_backups[1]
Virtual backup strategies_using_storage_snapshots_for_backups[1]Virtual backup strategies_using_storage_snapshots_for_backups[1]
Virtual backup strategies_using_storage_snapshots_for_backups[1]
gerdev
 
Livre blanc technique sur l&rsquo;architecture de référence
Livre blanc technique sur l&rsquo;architecture de référenceLivre blanc technique sur l&rsquo;architecture de référence
Livre blanc technique sur l&rsquo;architecture de référence
Microsoft France
 
High availability solutions
High availability solutionsHigh availability solutions
High availability solutions
Steve Xu
 
Dns320 manual 100
Dns320 manual 100Dns320 manual 100
Dns320 manual 100
markvw3
 

Was ist angesagt? (20)

JM White
JM WhiteJM White
JM White
 
Platform Migration Guide
Platform Migration GuidePlatform Migration Guide
Platform Migration Guide
 
EMC Enterprise Hybrid Cloud 2.5.1, Federation SDDC Edition: Backup Solution G...
EMC Enterprise Hybrid Cloud 2.5.1, Federation SDDC Edition: Backup Solution G...EMC Enterprise Hybrid Cloud 2.5.1, Federation SDDC Edition: Backup Solution G...
EMC Enterprise Hybrid Cloud 2.5.1, Federation SDDC Edition: Backup Solution G...
 
ISSU A PLANNED UPGRADE TOOL
ISSU A PLANNED UPGRADE TOOLISSU A PLANNED UPGRADE TOOL
ISSU A PLANNED UPGRADE TOOL
 
Automated provisioning using ibm tivoli intelligent orchestrator and enterpri...
Automated provisioning using ibm tivoli intelligent orchestrator and enterpri...Automated provisioning using ibm tivoli intelligent orchestrator and enterpri...
Automated provisioning using ibm tivoli intelligent orchestrator and enterpri...
 
Deployment guide series ibm total storage productivity center for data sg247140
Deployment guide series ibm total storage productivity center for data sg247140Deployment guide series ibm total storage productivity center for data sg247140
Deployment guide series ibm total storage productivity center for data sg247140
 
iPDC User Manual
iPDC User ManualiPDC User Manual
iPDC User Manual
 
EMC NetWorker Module for Microsoft SQL Server Administrators ...
EMC NetWorker Module for Microsoft SQL Server Administrators ...EMC NetWorker Module for Microsoft SQL Server Administrators ...
EMC NetWorker Module for Microsoft SQL Server Administrators ...
 
Rhel Tuningand Optimizationfor Oracle V11
Rhel Tuningand Optimizationfor Oracle V11Rhel Tuningand Optimizationfor Oracle V11
Rhel Tuningand Optimizationfor Oracle V11
 
WHITE PAPER▶ Software Defined Storage at the Speed of Flash
WHITE PAPER▶ Software Defined Storage at the Speed of FlashWHITE PAPER▶ Software Defined Storage at the Speed of Flash
WHITE PAPER▶ Software Defined Storage at the Speed of Flash
 
Backing up web sphere application server with tivoli storage management redp0149
Backing up web sphere application server with tivoli storage management redp0149Backing up web sphere application server with tivoli storage management redp0149
Backing up web sphere application server with tivoli storage management redp0149
 
A practical guide to tivoli sa nergy sg246146
A practical guide to tivoli sa nergy sg246146A practical guide to tivoli sa nergy sg246146
A practical guide to tivoli sa nergy sg246146
 
Newfies dialer Auto dialer Software
Newfies dialer Auto dialer SoftwareNewfies dialer Auto dialer Software
Newfies dialer Auto dialer Software
 
Cluster in linux
Cluster in linuxCluster in linux
Cluster in linux
 
Metatron Technology Consulting 's MySQL to PostgreSQL ...
Metatron Technology Consulting 's MySQL to PostgreSQL ...Metatron Technology Consulting 's MySQL to PostgreSQL ...
Metatron Technology Consulting 's MySQL to PostgreSQL ...
 
Ibm total storage productivity center for replication on linux sg247411
Ibm total storage productivity center for replication on linux sg247411Ibm total storage productivity center for replication on linux sg247411
Ibm total storage productivity center for replication on linux sg247411
 
Virtual backup strategies_using_storage_snapshots_for_backups[1]
Virtual backup strategies_using_storage_snapshots_for_backups[1]Virtual backup strategies_using_storage_snapshots_for_backups[1]
Virtual backup strategies_using_storage_snapshots_for_backups[1]
 
Livre blanc technique sur l&rsquo;architecture de référence
Livre blanc technique sur l&rsquo;architecture de référenceLivre blanc technique sur l&rsquo;architecture de référence
Livre blanc technique sur l&rsquo;architecture de référence
 
High availability solutions
High availability solutionsHigh availability solutions
High availability solutions
 
Dns320 manual 100
Dns320 manual 100Dns320 manual 100
Dns320 manual 100
 

Andere mochten auch

A look inside pandas design and development
A look inside pandas design and developmentA look inside pandas design and development
A look inside pandas design and development
Wes McKinney
 

Andere mochten auch (7)

Fast and energy-efficient eNVM based memory organisation at L3-L1 layers for ...
Fast and energy-efficient eNVM based memory organisation at L3-L1 layers for ...Fast and energy-efficient eNVM based memory organisation at L3-L1 layers for ...
Fast and energy-efficient eNVM based memory organisation at L3-L1 layers for ...
 
epoll() - The I/O Hero
epoll() - The I/O Heroepoll() - The I/O Hero
epoll() - The I/O Hero
 
A look inside pandas design and development
A look inside pandas design and developmentA look inside pandas design and development
A look inside pandas design and development
 
Unity Internals: Memory and Performance
Unity Internals: Memory and PerformanceUnity Internals: Memory and Performance
Unity Internals: Memory and Performance
 
Epoll - from the kernel side
Epoll -  from the kernel sideEpoll -  from the kernel side
Epoll - from the kernel side
 
Memory Management: What You Need to Know When Moving to Java 8
Memory Management: What You Need to Know When Moving to Java 8Memory Management: What You Need to Know When Moving to Java 8
Memory Management: What You Need to Know When Moving to Java 8
 
Understanding Memory Management In Spark For Fun And Profit
Understanding Memory Management In Spark For Fun And ProfitUnderstanding Memory Management In Spark For Fun And Profit
Understanding Memory Management In Spark For Fun And Profit
 

Ähnlich wie Memory Pools for C and C++

S Pii Plus+C+Library+Programmer+Guide
S Pii Plus+C+Library+Programmer+GuideS Pii Plus+C+Library+Programmer+Guide
S Pii Plus+C+Library+Programmer+Guide
guestd2fe1e
 
S Pii Plus+C+Library+Programmer+Guide
S Pii Plus+C+Library+Programmer+GuideS Pii Plus+C+Library+Programmer+Guide
S Pii Plus+C+Library+Programmer+Guide
guestd2fe1e
 
Disaster recovery solutions for ibm total storage san file system sg247157
Disaster recovery solutions for ibm total storage san file system sg247157Disaster recovery solutions for ibm total storage san file system sg247157
Disaster recovery solutions for ibm total storage san file system sg247157
Banking at Ho Chi Minh city
 
Disaster recovery solutions for ibm total storage san file system sg247157
Disaster recovery solutions for ibm total storage san file system sg247157Disaster recovery solutions for ibm total storage san file system sg247157
Disaster recovery solutions for ibm total storage san file system sg247157
Banking at Ho Chi Minh city
 
Seam reference guide
Seam reference guideSeam reference guide
Seam reference guide
athenadinh
 
Ref arch for ve sg248155
Ref arch for ve sg248155Ref arch for ve sg248155
Ref arch for ve sg248155
Accenture
 

Ähnlich wie Memory Pools for C and C++ (20)

Symantec Netbackup Delivering Performance Value Through Multiple De-duplicati...
Symantec Netbackup Delivering Performance Value Through Multiple De-duplicati...Symantec Netbackup Delivering Performance Value Through Multiple De-duplicati...
Symantec Netbackup Delivering Performance Value Through Multiple De-duplicati...
 
Db2 udb backup and recovery with ess copy services
Db2 udb backup and recovery with ess copy servicesDb2 udb backup and recovery with ess copy services
Db2 udb backup and recovery with ess copy services
 
S Pii Plus+C+Library+Programmer+Guide
S Pii Plus+C+Library+Programmer+GuideS Pii Plus+C+Library+Programmer+Guide
S Pii Plus+C+Library+Programmer+Guide
 
S Pii Plus+C+Library+Programmer+Guide
S Pii Plus+C+Library+Programmer+GuideS Pii Plus+C+Library+Programmer+Guide
S Pii Plus+C+Library+Programmer+Guide
 
Ibm power systems e870 and e880 technical overview and introduction
Ibm power systems e870 and e880 technical overview and introductionIbm power systems e870 and e880 technical overview and introduction
Ibm power systems e870 and e880 technical overview and introduction
 
Disaster recovery solutions for ibm total storage san file system sg247157
Disaster recovery solutions for ibm total storage san file system sg247157Disaster recovery solutions for ibm total storage san file system sg247157
Disaster recovery solutions for ibm total storage san file system sg247157
 
Disaster recovery solutions for ibm total storage san file system sg247157
Disaster recovery solutions for ibm total storage san file system sg247157Disaster recovery solutions for ibm total storage san file system sg247157
Disaster recovery solutions for ibm total storage san file system sg247157
 
IBM zEnterprise 114 Technical Guide
IBM zEnterprise 114 Technical GuideIBM zEnterprise 114 Technical Guide
IBM zEnterprise 114 Technical Guide
 
IBM Power 770 and 780 Technical Overview and Introduction
IBM Power 770 and 780 Technical Overview and IntroductionIBM Power 770 and 780 Technical Overview and Introduction
IBM Power 770 and 780 Technical Overview and Introduction
 
redp5222.pdf
redp5222.pdfredp5222.pdf
redp5222.pdf
 
Seam reference guide
Seam reference guideSeam reference guide
Seam reference guide
 
Ref arch for ve sg248155
Ref arch for ve sg248155Ref arch for ve sg248155
Ref arch for ve sg248155
 
Memory synthesis using_ai_methods
Memory synthesis using_ai_methodsMemory synthesis using_ai_methods
Memory synthesis using_ai_methods
 
devicetree-specification
devicetree-specificationdevicetree-specification
devicetree-specification
 
V mware service-def-private-cloud-11q1-white-paper
V mware service-def-private-cloud-11q1-white-paperV mware service-def-private-cloud-11q1-white-paper
V mware service-def-private-cloud-11q1-white-paper
 
AIX 5L Differences Guide Version 5.3 Edition
AIX 5L Differences Guide Version 5.3 EditionAIX 5L Differences Guide Version 5.3 Edition
AIX 5L Differences Guide Version 5.3 Edition
 
IBM enterprise Content Management
IBM enterprise Content ManagementIBM enterprise Content Management
IBM enterprise Content Management
 
Program Directory For CBPDO Installation and ServerPac Reference z/OS
Program Directory For CBPDO Installation and ServerPac Reference z/OSProgram Directory For CBPDO Installation and ServerPac Reference z/OS
Program Directory For CBPDO Installation and ServerPac Reference z/OS
 
Using Open Source Tools For STR7XX Cross Development
Using Open Source Tools For STR7XX Cross DevelopmentUsing Open Source Tools For STR7XX Cross Development
Using Open Source Tools For STR7XX Cross Development
 
Oracle
OracleOracle
Oracle
 

Mehr von Pathfinder Solutions

PathMATE Transformation Maps Mutx Controls
PathMATE Transformation Maps Mutx ControlsPathMATE Transformation Maps Mutx Controls
PathMATE Transformation Maps Mutx Controls
Pathfinder Solutions
 

Mehr von Pathfinder Solutions (10)

PathMATE Transformation Maps Mutx Controls
PathMATE Transformation Maps Mutx ControlsPathMATE Transformation Maps Mutx Controls
PathMATE Transformation Maps Mutx Controls
 
Multi Process Message Formats
Multi Process Message FormatsMulti Process Message Formats
Multi Process Message Formats
 
Interprocess Message Formats
Interprocess Message FormatsInterprocess Message Formats
Interprocess Message Formats
 
Index Based Instance Identification
Index Based Instance IdentificationIndex Based Instance Identification
Index Based Instance Identification
 
Distributed Deployment Model Driven Development
Distributed Deployment Model Driven DevelopmentDistributed Deployment Model Driven Development
Distributed Deployment Model Driven Development
 
UML Foundation for C Self Trimming
UML Foundation for C Self TrimmingUML Foundation for C Self Trimming
UML Foundation for C Self Trimming
 
Build Generation
Build GenerationBuild Generation
Build Generation
 
Blending Realized Code
Blending Realized CodeBlending Realized Code
Blending Realized Code
 
Binary Instance Loading
Binary Instance LoadingBinary Instance Loading
Binary Instance Loading
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)
 

Kürzlich hochgeladen

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Kürzlich hochgeladen (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

Memory Pools for C and C++

  • 1. Specialized Memory Pool for C and C++ Version 1.6 June 14, 2006 PathMATE Technical Notes Pathfinder Solutions LLC 33 Commercial Drive, Suite 2 Foxboro, MA 02035 USA www.PathfinderMDA.com 888-662-7284 ©2008 by Pathfinder Solutions
  • 2. Table Of Contents 1. Introduction........................................................................................... 1 2. Feature Overview................................................................................... 1 Types of Pools ........................................................................................ 1 Task-Specific General Purpose Pool........................................................ 1 Task-Specific Incident Pool ................................................................... 1 Default Pool........................................................................................ 2 Fault Handling .................................................................................... 2 Specification of Pool Block Sizes ................................................................ 2 General Purpose Task Pool Sizing .......................................................... 2 Incident Pool Sizing ............................................................................. 3 Default Pool........................................................................................ 4 Overall Feature Disabling ......................................................................... 4 Marking Summary ................................................................................... 4 3. Feature Implementation ........................................................................ 5 Mechanism Extensions ............................................................................. 5 Template Extensions................................................................................ 5 When to Apply General Purpose Task Pool............................................... 5 Task-Safety Report.................................................................................. 6 Usage Statistics Reporting ........................................................................ 6 4. Feature Design....................................................................................... 6 Classes .................................................................................................. 7 MemoryBlock...................................................................................... 7 PfdAllocationCluster ............................................................................. 7 PfdBufferManager <<singleton>> ........................................................ 7 PfdClusterManager .............................................................................. 8 PfdCriticalSection ................................................................................ 8 PfdLocalPool ....................................................................................... 8 PfdPoolBlock....................................................................................... 8 PfdPoolBlockSpecification ..................................................................... 9 PfdPoolSpecification............................................................................. 9 PfdTask ............................................................................................. 9 Associations ........................................................................................... 9 Domain Scenarios ..................................................................................10 Domain Services ....................................................................................21 PfdAllocationCluster Operations ................................................................21 PfdBufferManager Operations...................................................................21 PfdClusterManager Operations .................................................................22 ii
  • 3. PfdCriticalSection Operations ...................................................................23 PfdLocalPool Operations ..........................................................................23 PfdPoolBlock Operations ..........................................................................23 5. System Types....................................................................................... 23 Enumerates...........................................................................................23 User Defined Types ................................................................................23 iii
  • 4. Specialized Memory Pool for C and C++ 1. Introduction This Technical Note describes extensions to PathMATE’s C and C++ Maps to improve static buffer management. These extensions support task-local memory management pools. They are based on the buffer manager. 2. Feature Overview The goals of this feature are to:  Reduce the run-time overhead associated with dynamic memory allocation, which normally goes through the BufferManager, an intertask-safe resource.  Allow for the specific sizing and allocation of dynamic memory blocks for specific classes. This feature is built upon the base capabilities and characteristics of the BufferManager mechanism. This is a simple block management mechanism, where memory blocks of a small number of different sizes are arranged such that a request for a specific size block will result in the allocation of one of the smallest sized block available that will satisfy the request. Deallocation marks the originally allocated block as available again. One consequence of such a simple facility is that there is no notion of fragmentation – only contiguous blocks are allocated and deallocated, so no loss of efficiency over time is realized from varying usage and release patterns. Also, when a larger sized block is used to satisfy a smaller sized request, the entire block is allocated, so when it is deallocated it is again immediately available for use up to its complete size. Types of Pools All dynamically allocated memory elements come from one of three types of pools:  A task-specific general purpose pool  A task-specific incident pool  The default pool Note - the allocation of class instances from a pre-declared array is currently supported via the MaxIndex marking and the InstanceTable mechanism. Task-Specific General Purpose Pool You may define a memory pool for use within a single task. The pool provides task-local allocation and deallocation of memory blocks of a variety of user- specified sizes, in support of class instance data. Because it is task-local, the task-specific pool avoids the overhead of intertask safety mechanisms. Note: If a task-specific pool is defined and a class instance is created for a class that did not specify a MaxIndex (and thereby got its own array space), the task-specific pool is used. Task-Specific Incident Pool A task-specific incident pool may be specified. This pool is an array within the Task structure that holds pointers to available Incident instances. These are 1
  • 5. Specialized Memory Pool for C and C++ used to satisfy any incident allocations within the task. Once allocated, the address of the new incident is removed from the Task pool. Any Incidents freed within a Task that has an incident pool will go into that task’s pool, regardless of where they came from. If a Task with an incident pool runs out of Incidents and a request comes in for another, the incident pool is replenished from the default pool. If a Task with an incident pool runs fill up with available Incidents and another is released, ½ of the available incidents in the incident pool are returned to the default pool. To support possible incident parameters, when a task-specific incident pool is used, a task-specific data container pool is also used. The allocation/deallocation mechanics of this pool mirror that of the incident pool. Default Pool The default pool for dynamic memory allocation is the standard BufferManager pool. One instance of the BufferManager is allocated to each process in the system. Each instance provides intertask-safe allocation and deallocation of memory blocks of a variety of user-customizable sizes. If no other pool is specified for a dynamic memory request, or if an Incident is destined for the InterTaskIncidentQueue, the BufferManager pool is used. Fault Handling In the case of running out of memory the default action is to shut down the process in which the outage occurred. A new SW Service SW:RegisterForErrorGroup(enum fault_type, IncidentHandle handler) will be provided to allow for the user configurable handling of the SW_FAULT_DEPLETED_MEMORY fault. Specification of Pool Block Sizes General Purpose Task Pool Sizing Task-specific pools are allocated by specifying the “TaskPool-<process label>-<task name>” marking. The designer should identify the specific sizes of the dynamic elements within their task, and specify block sizes and counts appropriately. For example consider a scenario within the Robochef.FoodPrep domain where many recipes can be loaded and unloaded. Let's say the base RecipeStepSpec class instance overhead is 40 bytes, and a maximum of 900 instance of this class are expected. Assume it is allocated to its own domain and this specifies a domain-specific pool. One way to allocate space for those events is to specify 900 blocks of 40 bytes. A partial specification of this would be: System,Robochef,TaskPool-MAIN-SYS_TASK_ID_FP,... 900|40; ... The sample specification below creates task-specific pools for the tasks SYS_TASK_ID_MAIN and SYS_TASK_ID_AUX. Each pool contains 1024 blocks in each of three block sizes: System,CarShuffle,TaskPool-MAIN- SYS_TASK_ID_MAIN,1024|16;1024|48;1024`|196 System,CarShuffle,TaskPool-MAIN-SYS_TASK_ID_AUX,1024|88;1024|148;1024|306 2
  • 6. Specialized Memory Pool for C and C++ Optionally you may specify the reload and unload thresholds for each block size in the pool. When the number of blocks in the pool falls below the reload threshold, the pool will try to lock the buffer manager. If the buffer manager can't be locked, the pool will allocate the block. If the buffer manager can be locked, it will replenish the pool and then allocate the block. If the pool is empty, it will wait to obtain a lock on the buffer manager. When the number of free spots in the pool falls below the unload threshold, the pool will try to lock the buffer manager. If the buffer manager can't be locked, the pool will deallocate the block. If the buffer manager can be locked, the pool will release memory to the buffer manager and deallocate the block. If the pool has no free spots, the pool will wait to obtain a lock on the buffer manager and release memory back to the buffer manager. The default reload and unload thresholds are 5 or one less than the maximum count of items in the pool if the pools contains less than 5 items. Specify the reload and unload thresholds as follows: System,CarShuffle,TaskPool-MAIN-SYS_TASK_ID_MAIN,1024|16|2|4;1024|48;1024|196 System,CarShuffle,TaskPool-MAIN-SYS_TASK_ID_AUX,1024|88;1024|148;1024|306|20 In the example above, the main task pool of size 16 has a reload threshold of 2 and an unload threshold of 4. The size 48 and 196 pools use the default unload and reload threshold of 5. The aux task pool of size 306 has an unload threshold of 20 and a default reload threshold of 5. There is no way to specify a default reload threshold and a non-default unload threshold. This feature is not supported on Windows using Visual C++ 6.0 and on OSE. These platforms do not support an unblocked acquisition of a mutex. NOTE: Reload and unload thresholds are only supported in C++. Incident Pool Sizing Task-specific incident pools are allocated by specifying the “TaskIncidentPool-<process label>-<task name>” and “TaskIncidentParameterPool-<process label>-<task name>” markings. The value of these markings is the maximum number of pre-allocated incident or parameter blocks to be made available. They should be tuned to support the incident and incident parameter needs of your system during high usage scenarios. The compiler flag PATH_MEMORY_STATISTICS will turn on statistics collection in the BufferManager and the LocalPools. Each of these classes has a reportStatistics operation that can be called to print out statistics on memory usage which can help the designer tune the memory pool sizes. The sample specification below creates task-specific incident and parameter pools for the tasks SYS_TASK_ID_MAIN in the MON process, and SYS_TASK_ID_AUX in the PIO. Each task has 100 incidents and 50 parameters: System,CarShuffle,TaskIncidentPool-MON-SYS_TASK_ID_MAIN,100 System,CarShuffle,TaskIncidentParameterPool-MON-SYS_TASK_ID_MAIN,50 System,CarShuffle,TaskIncidentPool-PIO-SYS_TASK_ID_AUX,100 3
  • 7. Specialized Memory Pool for C and C++ System,CarShuffle,TaskIncidentParameterPool-PIO-SYS_TASK_ID_AUX,50 Default Pool Block sizes for the standard BufferManager pool can now be specified by the system marking “DefaultPoolSizes.” This property takes a list of sizes (numeric literals or symbolic constants) in increasing order. If “DefaultPoolSizes” is not specified the standard BufferManager pool will retain the default pool configuration as specified in the BufferManager mechanism module. The sample specification below explicitly calls out block sizes matching the delivered BufferManager implementation: System,CarShuffle,DefaultPoolSizes,2048|32;1638|40;1365|48;1024|64; 512|128;128|512;32|2048;1|0xFFFF Overall Feature Disabling All task-local pools (general, incident and parameter) are gated with the PATH_USE_LOCAL_POOLS compiler flag. This flag is set by default in generated project files and makefiles. Setting the system marking DisableLocalPools to "TRUE" prior to generating project files and makefiles will cause the PATH_USE_LOCAL_POOLS compiler flag not to be set, disabling all task-local pools. Marking Summary The following markings control this feature: Model Element Name Value System DefaultPoolSizes <count>|<size>;<count>|<size>… System DisableLocalPools TRUE, FALSE (FALSE) System TaskPool-<process id>-<task id> <count>|<size>;<count>|<size>… TaskIncidentPool-<process id>-<task System id> <size> TaskIncidentParameterPool-<process System id>-<task id> <size> Where: <count> and <size> are integer literals or symbolic constants, <process id>-<task id> specify a valid process label and task id (from domain marking) In addition to marking-based controls, all BufferManager capabilities, excluding specialized pools, can be replaced by native malloc and free calls by setting the compile switch PATH_NO_BUFFER_MANAGER. 4
  • 8. Specialized Memory Pool for C and C++ 3. Feature Implementation Mechanism Extensions Extensions to the C-Maps base mechanisms and system files take the existing SW_BufferManager mechanism and generalize it. These extensions allow for multiple instances, either task-local or intertask-safe, and configurable block sizes. To specify the block size for the default pool, the main() function calls a generated pool allocation and configuration function. The SW_Task structure adds the data member memoryPool to allow for a task-specific pool. If specified, this task-specific pool would be used in class instance and link structure allocations instead of the default pool. The SW_Task structure adds the data members incidentPool and parameterPool to allow for a task-specific incident pools. If specified, the task-specific pool would be used in SW_Incident_new, SW_Incident_deallocate, SW_DataContainer_new and SW_DataContainer_deallocate instead of the buffer manager. To support the use of class-specific pools, the functions SW_BufferManager_allocBlockForPool and SW_BufferManager_freeBlockForPool are added. To streamline operations on sets of allocations and deallocations (supporting task-specific incident and parameter pools) by reducing the overhead of entering and leaving the SW_BufferManager critical section, a transactional- style interface will be added to the SW_BufferManager. SW_BufferManager_startTransaction, SW_BufferManager_endTransaction, SW_BufferManager_fastAlloc and SW_BufferManager_fastFree functions will be added Template Extensions Extensions to the C-Maps code generation templates are applied to ensure the proper memory mechanisms are used in accord with the marking values. A pool allocation and configuration function is generated to specify the block sizes for the default pool. This function is called from the main() function. The generated function System_Run() is modified to create, configure, and delete task-specific pools as specified by markings. When to Apply General Purpose Task Pool Template modifications are required to ensure that only truly local requests are mode of the general purpose task pool. In order for a class to use this pool the following conditions must be met: - The class is in a specific fixed task, and not SYS_TASK_ANY. - The class is not statically allocated, and does not have a MaxIndex value specified indicating direct array storage. - The class is allocated to a task with a general purpose pool defined. 5
  • 9. Specialized Memory Pool for C and C++ - All actions where the class is CREATEd and DELETEd are allocated to the same fixed task. Task-Safety Report If only domain multi-task is implemented, then there will be no circumstances where the use of task-specific pools could result in an unsafe intertask memory access. However with domain operation multi-task or class multi- task support, it may be possible to specify that a single domain can run in multiple tasks. In this case, a set of templates will be run as part of code generation pre-processing to look for uses of task-specific pools that may incorrectly span task boundaries. For example, assume the Carshuffle VehicleHousing domain has some domain operations that run in SYS_TASK_ID_MAIN , and some domain operations that run in SYS_TASK_ID_AUX. If the class VH.Car does not specify a MaxIndex and is not statically initialized, task-specific pools are specified, and Car instances are CREATEd in the task SYS_TASK_ID_MAIN and DELETEd in the task SYS_TASK_ID_AUX, this will be highlighted as a run-time issue via a transformation Engine LOGERROR message. Allocating memory in one task and then deallocating it in another task is problematic if the pool specifications do not support the exact same size blocks. For example, if task T1 supports blocks of 16, 32 and 64 bytes and T2 supports blocks of 32 and 64 bytes, a problem occurs if a block of size 16 or less were allocated in T1 and deallocated in T2. For example, T1 receives a request to allocate a block of size 8. T1 chooses a block size of 16 because it is the closest block size to 8. When the block is deallocated in T2, the pool block chooses the first pool with size >= to 8. For T2, this is 32. The block, which is actually size 16, is now in a pool of size 32 blocks. If the size 16 block is allocated as if it is 32, memory corruption will occur as 16 bytes of the adjacent block in the buffer manager will be overwritten. Usage Statistics Reporting As a tool to designers to aid in the proper allocation of pools, simple statistics will be kept throughout each execution of the system, and reported upon system shutdown. For the default process pool and for each task-specific general purpose pool, the maximum number of blocks on a per-cluster (block- size) basis will be kept – a “high water” mark will be reported. In addition, the current number of blocks (per cluster) still in use at shutdown time will be reported. For the task-specific incident pool, the total number of incidents allocated and released will be reported per-task. (It is thought that deficit trends – where a large imbalance exists in this area might be useful information). All of the above statistic collection and report code is activated by the PATH_MEMORY_STATISTICS compile flag. 4. Feature Design 6
  • 10. Specialized Memory Pool for C and C++ PfdPoolSpecification PfdPoolBlockSpecification 1 A1 2 1..n size : Integer count : Intege r +pool_specification count : Integer reloadThreshold : Integer 1..* unloadThreshold : Integer +cluster_specification A15 1 <<singleton>> PfdBufferManager gHandle : PfdBufferManager emergencyReserve : Handle startTransaction() endTransaction() PfdClusterManager +manager A1 8 fastAlloc() A1 3 size Index : Integer fastFree() 1 maxAllocSize() 1 0..* nextFre eBlo ck() whichBlockIndex() +cluster_manager allocateCluster() reportError() 1 isAllocated() 1 0.. * allocBlock() freeBlock() PfdAllocationCluster A14 clusterIndex : Integer 0..* cluster : Handle A17 +top_cluster A1 freeBlockCount : Integer 0..1 1 +crit_section 0..1 nextFreeBlock() +first_cluster_with_free freeBlock() PfdCriticalSection 0..1 0..1 0..1 inUse : Mutex 0..1 A1 6 +cluster_allocated_from Enter() +next_cluster Leave() Try() A21 A22 +next_free_item 0 ..* 0..1 MemoryBlock Memory Management Software Mechanisms Class Diagram Classes MemoryBlock (U) A block of free memory residing in a local pool or buffer manager. PfdAllocationCluster (U) A block of memory divided up and allocated out in equal sized blocks. cluster (Handle): (U) Block of space managed by the cluster. This space is divided up into blocks of the appropriate size and allocated. clusterIndex (Integer): (U) The index of the cluster into the list of clusters held by the cluster manager. freeBlockCount (Integer): (U) The number of free blocks left within this cluster. PfdBufferManager <<singleton>> (U) Allocates and frees dynamic memory blocks efficiently by using a limited set of block sizes. The buffer manager is a singleton instance that can be accessed by any of the tasks in the program. The buffer manager is protected by a mutex so it can be accessed by multiple tasks. 7
  • 11. Specialized Memory Pool for C and C++ (U) The population of block sizes can be customized by specifying design markings. emergencyReserve (Handle): (U) Reserved memory to be released if memory runs out. Releasing the reserved memory will allow the system to terminate gracefully. gHandle (PfdBufferManager): (U) The singleton instance of the buffer manager. PfdClusterManager (U) Tracks all of the clusters holding memory blocks of the same size. The cluster manager creates clusters at initialization time and allocates new clusters as the existing clusters run out of memory blocks. sizeIndex (Integer): (U) The size of the block held by this cluster. PfdCriticalSection (U) A synchronization mechanism to support concurrent access to a shared resource. inUse (Mutex): (U) The mutex or critical section providing locking to the client tasks. The implementation is platform specific. PfdLocalPool (U) A pool of memory blocks of itemSize allocated from the buffer manager. The memory pool avoids the overhead of acquiring the critical section for the singleton buffer manager each time an allocation is done. (U) At startup, the pool acquires the buffer manager critical section and loads the pool. When the number of free blocks drops below the reloadThreshold, the pool attempts to acquire the buffer manager critical section and reload the pool. (U) If the number of empty slots in the pool falls below the unloadThreshold, the pool attempts to acquire the buffer manager critical section and returns memory to the buffer manager. itemSize (Integer): (U) The size of the memory blocks held in the pool in bytes. maxCount (Integer): (U) The maximum number of memory blocks that can be stored in the pool. nextAvailable (Integer): (U) The index of the next free block or -1 if no free blocks are available. reloadThreshold (Integer): (U) Start trying to acquire the lock on the buffer manger to reload the pool when the number of free blocks falls below this number. unloadThreshold (Integer): (U) Start trying to acquire the buffer manager lock to unload the pool when the number of free spaces falls below this number. PfdPoolBlock (U) A set of local memory pools of different sizes used exclusively by a particular task. poolCount (Integer): (U) The number of local pools in this block 8
  • 12. Specialized Memory Pool for C and C++ PfdPoolBlockSpecification (U) Defines the parameters for a set of memory pools. count (Integer): (U) The number of pools of different sizes available. PfdPoolSpecification (U) Defines the parameters for the memory blocks held by a memory pool. count (Integer): (U) The number of blocks of memory in the pool. reloadThreshold (Integer): (U) When the number of free blocks in the pool falls below this threshold, start attempting to acquire the lock on the buffer manager. size (Integer): (U) The size of each block of memory in the pool. unloadThreshold (Integer): (U) When the number of empty spots in the pool falls below this threshold, start attempting to acquire the lock on the buffer manager. PfdTask (U) A thread of control for dispatching events to state models and executing actions. Associations A1 : PfdCriticalSection crit_section (0..1)  A1  (*) PfdBufferManager description: (U) The critical section that protects the buffer manager as memory is allocated by multiple threads. SortOrder: FIFO A11 : PfdLocalPool pool_block (1..*)  A11  (1) PfdPoolBlock description: (U) A set of memory pools holding items of different sizes. SortOrder: FIFO A12 : PfdPoolSpecification pool_specification (1..*)  A12  (1) PfdPoolBlockSpecification description: (U) Defines all the memory pool sizes supported by the pool block. PoolSpecifications are order by ascending size across this association SortOrder: ascending A13 : PfdClusterManager cluster_manager (*)  A13  (1) PfdBufferManager description: (U) The cluster managers that perform allocations on the different block sizes. SortOrder: FIFO A14 : PfdAllocationCluster top_cluster (0..1)  A14  (1) PfdClusterManager description: (U) The first cluster of the specified size. SortOrder: FIFO A15 : PfdPoolBlockSpecification cluster_specification (1..*)  A15  (1) PfdBufferManager description: (U) Defines the set of memory block sizes supported by the buffer manager. 9
  • 13. Specialized Memory Pool for C and C++ SortOrder: FIFO A16 : PfdAllocationCluster next_cluster (0..1)  A16  (1) PfdAllocationCluster description: (U) The next cluster allocating blocks of the same size. SortOrder: FIFO A17 : PfdAllocationCluster first_cluster_with_free (0..1)  A17  (1) PfdClusterManager description: (U) First cluster managed by the manager that may contain a free block. SortOrder: FIFO A18 : PfdClusterManager manager (1)  A18  (*) PfdAllocationCluster description: (U) Defines the parent manager for this cluster. SortOrder: FIFO A19 : MemoryBlock item_pool (*)  A19  (1) PfdLocalPool description: (U) The set of free blocks in the local pool. This association is implemented as an array of size maxCount. The array holds the set of available blocks. Blocks may be freed to an empty spot in the array. The nextAvailable attribute keeps track of the first memory block stored in the array. SortOrder: FIFO A20 : PfdPoolBlock general_pool_block (0..1)  A20  (1) PfdTask description: (U) The general purpose local memory pool for this task. When linked, use this pool when allocating memory from this task. SortOrder: FIFO A21 : PfdAllocationCluster cluster_allocated_from (0..1)  A21  (*) MemoryBlock description: (U) A memory block when it is allocated points back to its cluster. When it is deallocated, the pointer is used to determine its owning cluster. SortOrder: FIFO A22 : MemoryBlock next_free_item (0..1)  A22  (0..1) PfdAllocationCluster description: (U) The free memory block in this cluster with the lowest address. The next memory block to be allocated. SortOrder: FIFO Domain Scenarios 10
  • 14. Specialized Memory Pool for C and C++ UNCLASSIFIED Allocate from Buffer Manager - New Cluster Required : Pfd BufferMana ger : exi sti ng : PfdCluste rManager PfdAllocationCluster : clie nt 1: allocBlock(Integer) Find the cluster manager 2: startTransaction(Boolean) for requested size. 3: whichBlockIndex(Integer) Try existing clusters to find one with a free block. 4: nextFreeBlock( ) 5: nextFreeBlock( ) 6: Return null 7: allocateCluster(Ref<PfdAllocationCluster>) can't find a free 8: <<create>> new : block. Allocate a PfdAllocationCluster new cluster. 9: nextFreeBlock( ) Find a new free block to prepare for the next allocation. 10: isAllocated(Handle) Mark allocated block with owning cluster. 11: Return Block Handle 12: Return Block Handle 13: endTransaction( ) 14: Return Block Handle Description: Allocate a block of memory from the buffer manager. For this nominal flow, a block of memory is successfully allocated from a newly allocated cluster. Preconditions: UNCLASSIF IED 1. Buffer manager is initialized. 2. Size of memory block requested is less than the maximum size supported by buffer manager configuration. 3. Operating system has sufficient free heap memory to allocate a new cluster. 4. Existing clusters of the size requested do not have any free blocks. Postconditions: 1. Buffer manager located and returned a handle to memory block of the appropriate size. Domain Scenario - Allocate from Buffer Manager - New Cluster Required 11
  • 15. Specialized Memory Pool for C and C++ UNCLASSIFIED Allocate from Buffer Manager - Out of Memory : Pfd BufferMa nager : existing : PfdClusterManager PfdAlloca tionCluster : client 1: allocBlock(Integer) Find the cluster manager 2: startTransaction(Boolean) for requested size. 3: whichBlockIndex(Integer) Try existing clusters to find one with a free block. 4: nextFreeBlock( ) No free blocks found in existing clusters. 5: nextFreeBlock( ) Allocatio n of a new cluster fails. 6: allocateCluster(Ref<PfdAllocationCluster>) 7: <<create>> new : PfdAlloca ti onCluster 8: reportError(sw_predefined_error_group_e group, sw_predefined_error_code_e) handlers for this error code are 9: endTransaction( ) called by PfdProcess. 10: Return NULL Description: Allocate a block of memory from the buffer manager. For this exceptional flow, a block of memory is can't be allocated because there are no free blocks and a new cluster can't be allocated because the operating system runs out of memory. Preconditions: 1. Buffer manager is initialized. 2. Size of memory block requested is less than the maximum size supported by buffer manager configuration. 3. Operating system does not have sufficient free heap memory to allocate a new cluster if necessary. Postconditions: 1. Out of memory error is reported to software mechanisms error handler. 2. Registered error handlers are called. UNCLASSIFIED Domain Scenario - Allocate from Buffer Manager - Out of memory 12
  • 16. Specialized Memory Pool for C and C++ UNCLASSIFIED Allocate from Buffer Manager - Nominal : PfdBufferManager : : PfdClusterManager PfdAllocationCluster : client 1: allocBlock(Integer) Fi nd the cluster manager 2: startTransaction(Boolean) for re queste d si ze. 3: whichBlockIndex(Integer) Try exi sti ng cluste rs to find one wi th a free b lock. 4: nextFreeBlock( ) Find a new fre e block to 5: nextFreeBlock( ) prepare for the next allocation. 6: isAllocated(Handle) Mark allocated block with owning cluster. 7: Return Block Handle 8: Return Block Handle 9: endTransaction( ) 10: Return Block Handle Descri ption: Allocate a block of me mory from the buffer manager. Fo r this nomina l flow, a block of memo ry is successfully allocated from existing cluster. Precond itions: 1. Buffer manager i s i nitialize d. 2. Size of memory block re queste d is less than the maximum size suppo rted by buffer mana ger configuration. 3. Exi sting clusters of the si ze reque sted hold fre e blocks. Po stcondi ti ons: 1. Buffer manager located a nd returned a handle to memory block of the appropriate size. UNCLASSIFIED Domain Scenario - Allocate from Buffer Manager 13
  • 17. Specialized Memory Pool for C and C++ UNCLASSIFIED Allocate from Lo cal Pool - Out of Memory : PfdPoolBlock : Pfd LocalP ool : PfdBufferManager : client 1: allocateItem(Integer) Locate local pool of size block requested 2: allocateItem( ) 3: startTransaction(Boolean) See Buffer Manager 4: fastAlloc(Integer) Attempt to reload Allocation Out of pool fails. 5: Return NULL Memory Scenarios for more details. 6: endTransaction( ) 7: Return NULL 8: Return NULL Description: Allocate a block of memory from a local pool. For this exceptional flow, the pool is empty and there is insufficient memory to reload the local pool. The allocation fails. Preconditions: 1. Buffer manager is initialized. 2. Local pools are initialized. 3. Size of memory block requested is less than the maximum size supported by local pool configuration. 4. Local pool of correct size is empty. 5. Buffer manager can't allocate enough memory to reload the local pool. Postconditions: 1. Local pool located and null handle is returned. UNCLASSIFIED Domain Scenario - Allocate from Local Pool - Out of Memory 14
  • 18. Specialized Memory Pool for C and C++ UNCLASSIFIED Allocate from Local Pool - Reload Required : PfdPoolBlock : PfdLocalPool : PfdBufferManager : client 1: allocateItem(Integer) Locate local pool of size block requested 2: allocateItem( ) 3: startTransaction(Bo olean) See Buffer Manager Allocate enough 4: fastAlloc(Integer) Allocation blocks to fill half Scenarios for more 5: Return Memory Block the pool. details. 6: endTransaction( ) Update next available block to prepare for next allocation. 7: Return Memory Block 8: Return Memory Block Description: Allocate a block of memory from a local pool. For this nominal flow, the pool is empty and is successfully reloaded before allocating a block. Preconditions: 1. Buffer manager is initialized. 2. Local pools are initialized. 3. Size of memory block requested is less than the maximum size supported by local pool configuration. 4. Local pool of correct size is empty. 5. Buffer manager contains sufficient free memory to support reloading the pool. Postconditions: 1. Local pool located and returned a handle to memory block of the appropriate size. UNCLASSIFIED Domain Scenario - Allocate from Local Pool - Reload required 15
  • 19. Specialized Memory Pool for C and C++ U NC LASSIFIED Allo cate from Lo cal Po ol - N omina l : PfdPoolBlock : PfdLocalPool : client 1: allocateItem(Intege r) Locate local pool of size block requested 2: allocateItem( ) Update next available block to prepare for next allocation. 3: Return Memory Block 4: Return Memory Block Description: Allocate a block of memory from a local pool. For this nominal flow, a block of memory is available in the local pool and no reload is necessary. Preconditions: 1. Buffer manager is initialized. 2. Local pools are initialized. 3. Size of memory block requested is less than the maximum size supported by local pool configuration. 4. Local pool contains a block of the correct size. Postconditions: 1. Local pool located and returned a handle to memory block of the appropriate size. UNCLASSIFIED Domain Scenario - Allocate from Local Pool 16
  • 20. Specialized Memory Pool for C and C++ UNCLASSIF IED Deallocate to Buffer Manager - Nominal : : Pfd Allocati onCluste r PfdBufferManager : client 1: freeBlock(Handle) 2: startTransaction(Boolean) Use the bytes before the memory block handle to find the cluster owning the block. 3: freeBlock(Handle) 4: endTransaction( ) Description: Deallocate a block of memory and release it to the buffer manager. For this nominal flow, a block of memory is successfully deallocated. Preconditions: 1. Buffer manager is initialized. 2. Block being deallocated was allocated from buffer manager. 3. Block being deallocated is non-NULL. Postconditions: 1. Memory block returned to free storage and is ready to be U NC LAS SIFIE D allocated again. Domain Scenario - Deallocate to Buffer Manager 17
  • 21. Specialized Memory Pool for C and C++ UNCLASSIFIED Deallocate to Local Pool - Unload Required : : PfdLocalPool : PfdPo olBlock PfdBufferManager : client 1: dea llocateItem(Integer, Handle ) 2: dea lloca teItem(Handle ) 3: startTransaction(Boolean) Return half the blocks in the pool 4: fastFree(Handle) back to the buffer 5: endTransaction( ) manager. Set next available and prepare for next allocation. Descri pti on: Deallocate a block of me mory a nd relea se i t to the loca l p ool. For this nomi nal flow, the local pool doe s not have any empty slo ts and the local pool must return memo ry back to the buffer manager. Precondi ti ons: 1. Buffer ma nager is initialized. 2. Block being deallocated was allocated from local pool or b uffer manager. 3. Block being deallocated is non-NULL. 4. Loca l p ool no fre e slots in it to store the ne wly freed block. Po stcondi ti ons: 1. Memory block re turned to free storage and i s ready to be allocated a gain. U NC LAS SIFIE D Domain Scenario - Deallocate to Local Pool - Unload required 18
  • 22. Specialized Memory Pool for C and C++ UNCLASSIFIED Deallocate to Local Pool - Nominal : : PfdLocalPool PfdPoolBlock : client 1: deallocateItem(Integer, Handle) 2: deallocateItem(Handle) Set next available and prepare for next allocation. Description: Deallocate a block of memory and release it to the local pool. For this nominal flow, the local pool has empty slots in it and no unload is required. Preconditions: 1. Buffer manager is initialized. 2. Block being deallocated was allocated from local pool or buffer manager. 3. Block being deallocated is non-NULL. 4. Local pool has at least one free slot in it to store the newly freed block. Postconditions: UNCLASSIFIED 1. Memory block returned to free storage and is ready to be allocated again. Domain Scenario - Deallocate to Local Pool 19
  • 23. Specialized Memory Pool for C and C++ UNCLASSIFIED Initia liz e B uffer Manag er - Out o f Me mo ry : create one clus ter manag er fo r PfdB ufferManag er each memo ry block size i n poo l speci fi cation. 1: <<create>> : PfdClusterManager 2: allocateCluster(Ref<PfdAllocationCluster>) 3: <<create>> : PfdAllocationCluster 4: reportE rror(sw_prede fi ned_erro r_g roup _e g roup , sw_predefi ned_erro r_co de_e) handlers for this error code are called by PfdProcess Description: The operating system runs out of memory while the buffer manager is initializing its clusters. An out of memory error is reported. Preconditions: 1. System is initializing. 2. Operating system has insufficient memory to allocate all the clusters. Postconditions: 1. Out of memory error is reported to software mechanisms error handler. 2. Registered error handlers are called. UNCLASSIFIED Domain Scenario - Initialize Buffer Manager - Out of Memory 20
  • 24. Specialized Memory Pool for C and C++ Initia lize B uffer Manage r UNC LAS SIFIE D : create one cluster manager for PfdBufferManager each memory block size in pool specification. 1: <<create>> : PfdClusterManage r 2: allocateCluster(Ref<PfdAllocationCluster>) 3: <<create>> : PfdAllocationCluster allocate a block of memory from the operating system of size = block size * block count D escription: set up next free item and The buffer manage r initializes its clusters. F or this nominal flow, free block count clusters are successfully allocate d fro m the operating syste m m emo ry manager. Precond itions: 1. S ystem is initia lizing. 2. Operating system has suffi cient memory to allocate all the clusters. Po stconditions: UNCLASSIFIED 1. Clusters are p opulated according to memory pool specifications. 2. B uffer m anager is read y to allocate new memory blocks. Domain Scenario - Initialize Buffer Manager Domain Services PfdAllocationCluster Operations PfdAllocationCluster:freeBlock (instance-based): (U) Return a memory block back to the free store so it can be allocated again. in: item_to_free (Handle): (U) The block to free. PfdAllocationCluster:nextFreeBlock (instance-based): (U) Returns the next free block in the cluster. Returns 0 if none are available. returns: (Handle) PfdBufferManager Operations PfdBufferManager:allocBlock (instance-based): (U) Allocate a block of memory of at least size and return a handle to it. returns: (Handle) in: size (Integer): (U) The minimum size of the memory block to allocate. PfdBufferManager:endTransaction (object-based): (U) Unlock the mutex for the buffer manager. PfdBufferManager:fastAlloc (object-based): (U) Allocate without locking the mutex. The client must call startTransaction before calling this member function. returns: (Handle) in: size (Integer): (U) The size of the memory block to be allocated. 21
  • 25. Specialized Memory Pool for C and C++ PfdBufferManager:fastFree (object-based): (U) Free without locking the mutex. The client must call startTransaction before calling this member function. in: block_to_free (Handle): (U) The handle to the block that will be returned to available free memory. PfdBufferManager:freeBlock (instance-based): (U) Put a block to the free store. The block is ready to be allocated again. in: block (Handle): (U) A handle to the block to be freed. Ignore NULL handles. PfdBufferManager:isAllocated (object-based): (U) Return TRUE if the block has already been allocated. Return FALSE if the block is free. returns: (Boolean) in: block_handle (Handle): (U) Check this memory block to see if it is allocated or free. PfdBufferManager:maxAllocSize (object-based): (U) Return the maximum size block that can be allocated from the buffer manager. returns: (Integer) PfdBufferManager:reportError (instance-based): (U) Report an memory error detected during allocation or deallocation. in: error_group (sw_predefined_error_group_e group): (U) Report an error belonging to this group. in: error_code (sw_predefined_error_code_e): (U) Report an error with this code. PfdBufferManager:startTransaction (object-based): (U) Obtain the mutex required for accessing the buffer manager. Return TRUE if the lock could be obtained. Return FALSE, if wait_for_critical was FALSE and the buffer manager lock could not be obtained without waiting. returns: (Boolean) in: wait_for_critical (Boolean): (U) If TRUE, block while waiting for the buffer manager mutex. If FALSE, only lock the mutex if it can acquired without waiting. PfdBufferManager:whichBlockIndex (object-based): (U) Return the index of the cluster used to allocate a block of the requested size. returns: (Integer) in: request_size (Integer): (U) The size of the block requested. PfdClusterManager Operations PfdClusterManager:allocateCluster (instance-based): (U) Allocate a new cluster for this manager. Return TRUE if successful. returns: (Boolean) in: previous_cluster (Ref<PfdAllocationCluster>): (U) The previous cluster in the chain of clusters. PfdClusterManager:nextFreeBlock (instance-based): (U) Return a free block from an allocation cluster. Return 0 if all clusters are used and no new clusters can be allocated. returns: (Handle) 22
  • 26. Specialized Memory Pool for C and C++ PfdCriticalSection Operations PfdCriticalSection:Enter (instance-based): (U) Lock the critical section. Suspend the task and wait if the critical section is locked by another task. PfdCriticalSection:Leave (instance-based): (U) Unlock the critical section so that other tasks may access the shared resource. PfdCriticalSection:Try (instance-based): (U) Try to lock the critical section. Don't wait if the critical section is locked by another task. Return TRUE if the critical section was sucessfully locked. Return FALSE if the critical section ws not successfully locked. To acquire the lock, the client must call Enter to wait for the lock to become availble or poll using Try. returns: (Boolean) PfdLocalPool Operations PfdLocalPool:allocateItem (instance-based): (U) Allocated a block of memory from the pool. Return a pointer to the block or 0 if the block can't be allocated. returns: (Handle) PfdLocalPool:deallocateItem (instance-based): (U) Free a block of memory. in: item (Handle): (U) A pointer to the block of memory to free. PfdLocalPool:reload (instance-based): (U) Reload the pool with more blocks from the buffer manager if it is empty or almost out. PfdLocalPool:unload (instance-based): (U) Return some of the empty memory to the buffer manager if the pool is completely full or nearly full. PfdPoolBlock Operations PfdPoolBlock:allocateItem (instance-based): (U) Find the correct pool containing the correct memory block size. Allocate a block of memory from the pool and return a pointer to the memory. returns: (Handle) in: size (Integer): (U) The size of the block of memory to allocate. PfdPoolBlock:deallocateItem (instance-based): (U) Return a memory block to the pool for its size. in: item_size (Integer): (U) The size of the memory block pointed to by item in bytes. in: item (Handle): (U) A handle to the block of memory to be freed. 5. System Types Enumerates User Defined Types Mutex : base: Integer PfdBufferManager : base: Integer sw_predefined_error_code_e : base: Integer sw_predefined_error_group_e group : base: Integer 23