Shared Persistent Heap Data Environment Manual  1.1.0
Macros | Typedefs | Functions
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. More...
 
__C__ SASSimpleHeap_t SASSimpleHeapCreate (block_size_t heap_size)
 Allocate a SAS block large enough to contain the requested SAS Simple Heap. More...
 
__C__ int SASSimpleHeapDestroy (SASSimpleHeap_t heap)
 Destroy a SASSimpleHeap_t and free the shared storage block. More...
 
__C__ block_size_t SASSimpleHeapFreeSpace (SASSimpleHeap_t heap)
 Return the available space from Simple Heap heap. More...
 
__C__ int SASSimpleHeapEmpty (SASSimpleHeap_t heap)
 Return if the Simple Heap heap has no space left. More...
 
__C__ void * SASSimpleHeapAlloc (SASSimpleHeap_t heap, block_size_t alloc_size)
 Allocate a block of alloc_size bytes from Simple Heap heap. More...
 
__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. More...
 
__C__ SASSimpleHeap_t SASSimpleHeapNearFind (void *nearObj)
 Find the associate SASSimpleHeap_t control block near nearObj. More...
 
__C__ void * SASSimpleHeapNearAlloc (void *nearObj, long allocSize)
 Allocate a block of alloc_size bytes from Simple Heap nearObj. More...
 
__C__ void SASSimpleHeapNearDealloc (void *memAddr, long allocSize)
 Deallocate the memory block memAddr of size allocSize. More...
 
__C__ int SASSimpleHeapDestroyNoLock (SASSimpleHeap_t heap)
 Destroy a SASSimpleHeap_t and free the shared storage block. More...
 
__C__ block_size_t SASSimpleHeapFreeSpaceNoLock (SASSimpleHeap_t heap)
 Return the available space from Simple Heap heap. More...
 
__C__ void * SASSimpleHeapAllocNoLock (SASSimpleHeap_t heap, block_size_t alloc_size)
 Allocate a block of alloc_size bytes from Simple Heap heap. More...
 
__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. More...
 
__C__ void * SASSimpleHeapNearAllocNoLock (void *nearObj, long allocSize)
 Allocate a block of allocSize bytes from Simple Heap heap. More...
 
__C__ void SASSimpleHeapNearDeallocNoLock (void *memAddr, long allocSize)
 Deallocate the memory block memAddr of size allocSize. More...
 
__C__ int SASSimpleHeapEmptyNoLock (SASSimpleHeap_t heap)
 Return if the Simple Heap heap has not space left. More...
 

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

__C__ void* SASSimpleHeapAlloc ( SASSimpleHeap_t  heap,
block_size_t  alloc_size 
)

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
heapHandle of a SAS Simple Heap.
alloc_sizeSize 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.
__C__ void* SASSimpleHeapAllocNoLock ( SASSimpleHeap_t  heap,
block_size_t  alloc_size 
)

Allocate a block of alloc_size bytes from Simple Heap heap.

Similar to SASSimpleHeapAlloc but do not hold any write lock.

Parameters
heapHandle of a SAS Simple Heap.
alloc_sizeSize 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.
__C__ SASSimpleHeap_t SASSimpleHeapCreate ( block_size_t  heap_size)

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_sizeSize of the Simple Heap to create.
Returns
A handle to the created SASSimpleHeap_t.
__C__ int SASSimpleHeapDestroy ( SASSimpleHeap_t  heap)

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
heapHandle of the SASSimpleHeap_t to be destroyed.
Returns
0 indicates success, otherwise failure.
__C__ int SASSimpleHeapDestroyNoLock ( SASSimpleHeap_t  heap)

Destroy a SASSimpleHeap_t and free the shared storage block.

Similar to SASSimpleHeapDestroy but do not hold any write lock.

Parameters
heaphandle of the SASSimpleHeap_t to be destroyed.
Returns
a 0 value indicates success, otherwise failure.
__C__ int SASSimpleHeapEmpty ( SASSimpleHeap_t  heap)

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
heapHandle of a SAS Simple Heap.
Returns
0 if heap is not empty and has some space left for additional storage or 1 otherwise.
__C__ int SASSimpleHeapEmptyNoLock ( SASSimpleHeap_t  heap)

Return if the Simple Heap heap has not space left.

Similar to SASSimpleHeapEmpty but do not hold any write lock.

Parameters
heapHandle of a SAS Simple Heap.
Returns
0 if heap is not empty and has some space left for additional storage or 1 otherwise.
__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.

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

Parameters
heapHandle of a SAS Simple Heap.
free_blockMemory block previously allocated using SASSimpleHeapAlloc function.
alloc_sizeSize 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.
__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.

Similar to SASSimpleHeapFree but do not hold any lock.

Parameters
heapHandle of a SAS Simple Heap.
free_blockMemory block previously allocated using SASSimpleHeapAlloc function.
alloc_sizeSize 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.
__C__ block_size_t SASSimpleHeapFreeSpace ( SASSimpleHeap_t  heap)

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
heapHandle of a SAS Simple Heap.
Returns
Size in bytes of the remaining free Heap.
__C__ block_size_t SASSimpleHeapFreeSpaceNoLock ( SASSimpleHeap_t  heap)

Return the available space from Simple Heap heap.

Similar to SASSimpleHeapFreeSpace but do not hold any write lock.

Parameters
heapHandle of a SAS Simple Heap.
Returns
The size in bytes of the available space on heap.
__C__ SASSimpleHeap_t SASSimpleHeapInit ( void *  heap_block,
sas_type_t  sasType,
block_size_t  heap_size 
)

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_blockBlock of allocated SAS storage.
sasTypeType of SAS object (should contain SAS_SIMPLEHEAP_TYPE type).
heap_sizeSize of the simple heap within the block.
Returns
A handle to the initialized SASSimpleHeap_t or 0 if an error occurs.
__C__ void* SASSimpleHeapNearAlloc ( void *  nearObj,
long  allocSize 
)

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
nearObjHandle of a SAS Simple Heap.
allocSizeSize 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.
__C__ void* SASSimpleHeapNearAllocNoLock ( void *  nearObj,
long  allocSize 
)

Allocate a block of allocSize bytes from Simple Heap heap.

Similar to SASSimpleHeapNearAlloc but do not hold any write lock.

Parameters
nearObjHandle of a SAS Simple Heap.
allocSizeSize 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.
__C__ void SASSimpleHeapNearDealloc ( void *  memAddr,
long  allocSize 
)

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
memAddrHandle of a SAS Simple Heap.
allocSizeSize 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.
__C__ void SASSimpleHeapNearDeallocNoLock ( void *  memAddr,
long  allocSize 
)

Deallocate the memory block memAddr of size allocSize.

Similar to SASSimpleHeapNearDealloc but do not hold any write lock.

Parameters
memAddrHandle of a SAS Simple Heap.
allocSizeSize 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.
__C__ SASSimpleHeap_t SASSimpleHeapNearFind ( void *  nearObj)

Find the associate SASSimpleHeap_t control block near nearObj.

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