Loading...
Searching...
No Matches
sassimpleheap.h File Reference

Shared Address Space Simple Heap. More...

`#include "sastype.h"`

Go to the source code of this file.

## Typedefs

typedef void * | SASSimpleHeap_t
| Handle to SAS Simple Space. The type is SAS_RUNTIME_SIMPLEHEAP.

## Functions

__C__ SASSimpleHeap_t | SASSimpleHeapInit (void *heap_block, sas_type_t sasType, block_size_t heap_size)
| Initialize a shared storage as a simple heap.
__C__ SASSimpleHeap_t | SASSimpleHeapCreate (block_size_t heap_size)
| Allocate a SAS block large enough to contain the requested SAS Simple Heap.
__C__ int | SASSimpleHeapDestroy (SASSimpleHeap_t heap)
| Destroy a SASSimpleHeap_t and free the shared storage block.
__C__ block_size_t | SASSimpleHeapFreeSpace (SASSimpleHeap_t heap)
| Return the available space from Simple Heap heap.
__C__ int | SASSimpleHeapEmpty (SASSimpleHeap_t heap)
| Return if the Simple Heap heap has no space left.
__C__ void * | SASSimpleHeapAlloc (SASSimpleHeap_t heap, block_size_t alloc_size)
| Allocate a block of alloc_size bytes from Simple Heap heap.
__C__ int | SASSimpleHeapFree (SASSimpleHeap_t heap, void *free_block, block_size_t alloc_size)
| Deallocate the memory block free_block of size alloc_size from Simple Heap heap.
__C__ SASSimpleHeap_t | SASSimpleHeapNearFind (void *nearObj)
| Find the associate SASSimpleHeap_t control block near nearObj.
__C__ void * | SASSimpleHeapNearAlloc (void *nearObj, long allocSize)
| Allocate a block of alloc_size bytes from Simple Heap nearObj.
__C__ void | SASSimpleHeapNearDealloc (void *memAddr, long allocSize)
| Deallocate the memory block memAddr of size allocSize.
__C__ int | SASSimpleHeapDestroyNoLock (SASSimpleHeap_t heap)
| Destroy a SASSimpleHeap_t and free the shared storage block.
__C__ block_size_t | SASSimpleHeapFreeSpaceNoLock (SASSimpleHeap_t heap)
| Return the available space from Simple Heap heap.
__C__ void * | SASSimpleHeapAllocNoLock (SASSimpleHeap_t heap, block_size_t alloc_size)
| Allocate a block of alloc_size bytes from Simple Heap heap.
__C__ int | SASSimpleHeapFreeNoLock (SASSimpleHeap_t heap, void *free_block, block_size_t alloc_size)
| Deallocate the memory block free_block of size alloc_size from Simple Heap heap.
__C__ void * | SASSimpleHeapNearAllocNoLock (void *nearObj, long allocSize)
| Allocate a block of allocSize bytes from Simple Heap heap.
__C__ void | SASSimpleHeapNearDeallocNoLock (void *memAddr, long allocSize)
| Deallocate the memory block memAddr of size allocSize.
__C__ int | SASSimpleHeapEmptyNoLock (SASSimpleHeap_t heap)
| Return if the Simple Heap heap has not space left.

## Detailed Description

Shared Address Space Simple Heap.

Allocate a SAS block to be used as an heap using its internal functions to allocate/deallocate objects. The heap is created with function SASSimpleHeapCreate and destroyed with SASSimpleHeapDestroy. Objects are allocated with function SASSimpleHeapAlloc, SASSimpleHeapNearAlloc, and with their NoLock variants. The objects are freed using SASSimpleHeapFree, SASSimpleHeapNearDealloc, and with their NoLock variants.

## Function Documentation

## SASSimpleHeapAlloc()

__C__ void * SASSimpleHeapAlloc | ( | SASSimpleHeap_t | heap,
|  | block_size_t | alloc_size )

extern

Allocate a block of alloc_size bytes from Simple Heap heap.

The sas_type_t must be SAS_RUNTIME_SIMPLEHEAP. The functions holds an exclusive write while reading the empty spaces from heap object.

Parameters

  heap | Handle of a SAS Simple Heap.
  alloc_size | Size in byte to allocate.

Returns
  A valid memory address or NULL if heap is not a SAS_RUNTIME_SIMPLEHEAP or if there is no space left in heap.

## SASSimpleHeapAllocNoLock()

__C__ void * SASSimpleHeapAllocNoLock | ( | SASSimpleHeap_t | heap,
|  | block_size_t | alloc_size )

extern

Allocate a block of alloc_size bytes from Simple Heap heap.

Similar to SASSimpleHeapAlloc but do not hold any write lock.

Parameters

  heap | Handle of a SAS Simple Heap.
  alloc_size | Size in byte to allocate.

Returns
  A valid memory address or NULL if heap is not a SAS_RUNTIME_SIMPLEHEAP or if there is no space left in heap.

## SASSimpleHeapCreate()

__C__ SASSimpleHeap_t SASSimpleHeapCreate | ( | block_size_t | heap_size | ) |

extern

Allocate a SAS block large enough to contain the requested SAS Simple Heap.

Create and initialize a Simple Heap. The storage block must be power of two in size and SAS type returned is SAS_RUNTIME_SIMPLEHEAP.

Parameters

  heap_size | Size of the Simple Heap to create.

Returns
  A handle to the created SASSimpleHeap_t.

## SASSimpleHeapDestroy()

__C__ int SASSimpleHeapDestroy | ( | SASSimpleHeap_t | heap | ) |

extern

Destroy a SASSimpleHeap_t and free the shared storage block.

The sas_type_t must be SAS_RUNTIME_SIMPLEHEAP. Destroy holds an exclusive lock write while clearing the control blocks and freeing the SAS block.

Parameters

  heap | Handle of the SASSimpleHeap_t to be destroyed.

Returns
  0 indicates success, otherwise failure.

## SASSimpleHeapDestroyNoLock()

__C__ int SASSimpleHeapDestroyNoLock | ( | SASSimpleHeap_t | heap | ) |

extern

Destroy a SASSimpleHeap_t and free the shared storage block.

Similar to SASSimpleHeapDestroy but do not hold any write lock.

Parameters

  heap | handle of the SASSimpleHeap_t to be destroyed.

Returns
  a 0 value indicates success, otherwise failure.

## SASSimpleHeapEmpty()

__C__ int SASSimpleHeapEmpty | ( | SASSimpleHeap_t | heap | ) |

extern

Return if the Simple Heap heap has no space left.

The sas_type_t must be SAS_RUNTIME_SIMPLEHEAP. The functions holds an exclusive write while reading the empty spaces from heap object.

Parameters

  heap | Handle of a SAS Simple Heap.

Returns
  0 if heap is not empty and has some space left for additional storage or 1 otherwise.

## SASSimpleHeapEmptyNoLock()

__C__ int SASSimpleHeapEmptyNoLock | ( | SASSimpleHeap_t | heap | ) |

extern

Return if the Simple Heap heap has not space left.

Similar to SASSimpleHeapEmpty but do not hold any write lock.

Parameters

  heap | Handle of a SAS Simple Heap.

Returns
  0 if heap is not empty and has some space left for additional storage or 1 otherwise.

## SASSimpleHeapFree()

__C__ int SASSimpleHeapFree | ( | SASSimpleHeap_t | heap,
|  | void * | free_block,
|  | block_size_t | alloc_size )

extern

Deallocate the memory block free_block of size alloc_size from Simple Heap heap.

The sas_type_t must be SAS_RUNTIME_SIMPLEHEAP. The functions holds an exclusive write while freeing the allocated block from heap.

Parameters

  heap | Handle of a SAS Simple Heap.
  free_block | Memory block previously allocated using SASSimpleHeapAlloc function.
  alloc_size | Size in bytes of the allocated block size.

Returns
  0 if the block was successfully freed, -1 if alloc_size is incorrect, or -2 if heap is not a SAS_RUNTIME_SIMPLEHEAP.

## SASSimpleHeapFreeNoLock()

__C__ int SASSimpleHeapFreeNoLock | ( | SASSimpleHeap_t | heap,
|  | void * | free_block,
|  | block_size_t | alloc_size )

extern

Deallocate the memory block free_block of size alloc_size from Simple Heap heap.

Similar to SASSimpleHeapFree but do not hold any lock.

Parameters

  heap | Handle of a SAS Simple Heap.
  free_block | Memory block previously allocated using SASSimpleHeapAlloc function.
  alloc_size | Size in bytes of the allocated block size.

Returns
  0 if the block was successfully freed, -1 if alloc_size is incorrect, or -2 if heap is not a SAS_RUNTIME_SIMPLEHEAP.

## SASSimpleHeapFreeSpace()

__C__ block_size_t SASSimpleHeapFreeSpace | ( | SASSimpleHeap_t | heap | ) |

extern

Return the available space from Simple Heap heap.

The sas_type_t must be SAS_RUNTIME_SIMPLEHEAP. The functions holds an exclusive write while reading the empty spaces from heap object.

Parameters

  heap | Handle of a SAS Simple Heap.

Returns
  Size in bytes of the remaining free Heap.

## SASSimpleHeapFreeSpaceNoLock()

__C__ block_size_t SASSimpleHeapFreeSpaceNoLock | ( | SASSimpleHeap_t | heap | ) |

extern

Return the available space from Simple Heap heap.

Similar to SASSimpleHeapFreeSpace but do not hold any write lock.

Parameters

  heap | Handle of a SAS Simple Heap.

Returns
  The size in bytes of the available space on heap.

## SASSimpleHeapInit()

__C__ SASSimpleHeap_t SASSimpleHeapInit | ( | void * | heap_block,
|  | sas_type_t | sasType,
|  | block_size_t | heap_size )

extern

Initialize a shared storage as a simple heap.

Initialize the control blocks within the specified storage block as a Simple Heap. The store block must be power of two in size and have the same power of two (or better) alignment. The SAS type created is SAS_RUNTIME_SIMPLEHEAP.

Parameters

  heap_block | Block of allocated SAS storage.
  sasType | Type of SAS object (should contain SAS_SIMPLEHEAP_TYPE type).
  heap_size | Size of the simple heap within the block.

Returns
  A handle to the initialized SASSimpleHeap_t or 0 if an error occurs.

## SASSimpleHeapNearAlloc()

__C__ void * SASSimpleHeapNearAlloc | ( | void * | nearObj,
|  | long | allocSize )

extern

Allocate a block of alloc_size bytes from Simple Heap nearObj.

The address nearObj is used to find the associated Simple Heap object. The sas_type_t must be SAS_RUNTIME_SIMPLEHEAP. The functions holds an exclusive write while allocating from heap.

Parameters

  nearObj | Handle of a SAS Simple Heap.
  allocSize | Size in byte to allocate.

Returns
  A valid memory address or NULL if heap if not a SAS_RUNTIME_SIMPLEHEAP or if there is no space left in heap.

## SASSimpleHeapNearAllocNoLock()

__C__ void * SASSimpleHeapNearAllocNoLock | ( | void * | nearObj,
|  | long | allocSize )

extern

Allocate a block of allocSize bytes from Simple Heap heap.

Similar to SASSimpleHeapNearAlloc but do not hold any write lock.

Parameters

  nearObj | Handle of a SAS Simple Heap.
  allocSize | Size in byte to allocate.

Returns
  A valid memory address or NULL if heap is not a SAS_RUNTIME_SIMPLEHEAP or if there is no space left in heap.

## SASSimpleHeapNearDealloc()

__C__ void SASSimpleHeapNearDealloc | ( | void * | memAddr,
|  | long | allocSize )

extern

Deallocate the memory block memAddr of size allocSize.

The address memAddr is used to find the associated Simple Heap object. The sas_type_t must be SAS_RUNTIME_SIMPLEHEAP. The functions holds an exclusive write while reading the empty spaces from heap object.

Parameters

  memAddr | Handle of a SAS Simple Heap.
  allocSize | Size in bytes of the allocated block size.

Returns
  0 if the block was successfully freed, -1 if alloc_size is incorrect, or -2 if heap is not a SAS_RUNTIME_SIMPLEHEAP.

## SASSimpleHeapNearDeallocNoLock()

__C__ void SASSimpleHeapNearDeallocNoLock | ( | void * | memAddr,
|  | long | allocSize )

extern

Deallocate the memory block memAddr of size allocSize.

Similar to SASSimpleHeapNearDealloc but do not hold any write lock.

Parameters

  memAddr | Handle of a SAS Simple Heap.
  allocSize | Size in bytes of the allocated block size.

Returns
  0 if the block was successfully freed, -1 if alloc_size is alloc_size if incorrect, or -2 if heap is not a SAS_RUNTIME_SIMPLEHEAP.

## SASSimpleHeapNearFind()

__C__ SASSimpleHeap_t SASSimpleHeapNearFind | ( | void * | nearObj | ) |

extern

Find the associate SASSimpleHeap_t control block near nearObj.

Parameters

  nearObj | Handle of a SAS Simple Heap.

Returns
  Associated Simple Heap handler or NULL if the address nearObj is not a SASSimpleHeap_t.