OPIC
Object Persistence In C
Related Functions
OPHeap Struct Reference

Memory allocator object with persistent storage on disk. More...

Related Functions

(Note that these are not member functions.)

OPHeapOPHeapOpen (const char *path, int flags)
 OPHeap constructor which opens a memory mapped file to hold the heap. More...
 
OPHeapOPHeapOpenTmp ()
 OPHeap constructor which uses a temporal file to hold the heap. More...
 
void OPHeapMSync (OPHeap *heap)
 Flushes changes in OPHeap to the file that holds the heap. More...
 
void OPHeapClose (OPHeap *heap)
 Flushes the changes in OPHeap to disk, closes the file, and un-maps the memory. More...
 
void OPHeapStorePtr (OPHeap *heap, void *ptr, int pos)
 Store a pointer to a root pointer slot in OPHeap. More...
 
void * OPHeapRestorePtr (OPHeap *heap, int pos)
 Restore a pointer from specified root pointer slot. More...
 
void * OPMalloc (OPHeap *heap, size_t size) __attribute__((malloc))
 Allocate an object from OPHeap with given size. More...
 
void * OPCalloc (OPHeap *heap, size_t num, size_t size) __attribute__((malloc))
 Allocate a chunk of memory filled with 0s. More...
 
void * OPMallocAdviced (OPHeap *heap, size_t size, int advice) __attribute__((malloc))
 Allocate an object of given size with an arena hint. More...
 
void * OPCallocAdviced (OPHeap *heap, size_t num, size_t size, int advice) __attribute__((malloc))
 Allocate a chunk of memory filled with 0s with an arena hint. More...
 
void OPDealloc (void *addr)
 Dealloc an object created by OPHeap. More...
 
static OPHeapObtainOPHeap (void *addr)
 Given any pointer in the OPHeap, returns the pointer to OPHeap. More...
 

Detailed Description

Memory allocator object with persistent storage on disk.

Friends And Related Function Documentation

◆ OPHeapOpen()

OPHeap * OPHeapOpen ( const char *  path,
int  flags 
)
related

OPHeap constructor which opens a memory mapped file to hold the heap.

Opens a memory mapped file to hold the heap. User can use the flags to control the behavior for opening the file. The flag must include one of the following modes: O_RDONLY, O_WRONLY, or O_RDWR. These flags coresponds to read-only, write-only, or read/write. In addition, user can bitwise-or the other flags open() supports. (system dependent). See man OPEN(2) for more details.

To create an empty heap with new file, use the O_CREAT flag. For using previous saved OPHeap file, simply specify the path to the existing OPHeap file and you're all set.

If there were any errors on opening the file, the errno would be set appropriately.

This constructor is thread safe.

Parameters
pathPath to file that holds the heap.
flagsflags passed to the open() system call.
Returns
An OPHeap instance if succeeded, otherwise NULL.
OPHeap* heap;
// creates new file if the file wasn't present.
heap = OPHeapOpen("/path/to/my/opheap", O_RDWR | O_CREAT);
// work on the heap

◆ OPHeapOpenTmp()

OPHeap * OPHeapOpenTmp ( )
related

OPHeap constructor which uses a temporal file to hold the heap.

The temporal file would get deleted after the heap is closed or the process finished.

If there were any errors on opening the file, the errno would be set appropriately.

This constructor is thread safe.

Returns
An OPHeap instance if succeeded, otherwise NULL.
OPHeap* heap;
heap = OPHeapOpenTmp();
// work on the heap

◆ OPHeapMSync()

void OPHeapMSync ( OPHeap heap)
related

Flushes changes in OPHeap to the file that holds the heap.

This method would block until the synchronization is complete. If there were any error on msync, the errno would be set appropriately.

This method is thread safe.

Parameters
heapthe OPHeap instance to synchronize memory to disk.

◆ OPHeapClose()

void OPHeapClose ( OPHeap heap)
related

Flushes the changes in OPHeap to disk, closes the file, and un-maps the memory.

Parameters
heapthe OPHeap instance to close.

◆ OPHeapStorePtr()

void OPHeapStorePtr ( OPHeap heap,
void *  ptr,
int  pos 
)
related

Store a pointer to a root pointer slot in OPHeap.

Parameters
heapOPHeap instance.
ptrthe pointer we want to store in root pointer slot.
posindex in the root pointer slot. 0 <= pos < 8.

◆ OPHeapRestorePtr()

void * OPHeapRestorePtr ( OPHeap heap,
int  pos 
)
related

Restore a pointer from specified root pointer slot.

Parameters
heapOPHeap instance.
posindex in the root pointer slot. 0 <= pos < 8.
Returns
The pointer we stored in the root pointer slot.

◆ OPMalloc()

void * OPMalloc ( OPHeap heap,
size_t  size 
)
related

Allocate an object from OPHeap with given size.

Parameters
heapOPHeap instance.
sizethe size of object.
Returns
pointer to the object allocated.

◆ OPCalloc()

void * OPCalloc ( OPHeap heap,
size_t  num,
size_t  size 
)
related

Allocate a chunk of memory filled with 0s.

Parameters
heapOPHeap instance.
numnumber of contiguous objects.
sizethe size of an object.
Returns
pointer to the memory allocated.

◆ OPMallocAdviced()

void * OPMallocAdviced ( OPHeap heap,
size_t  size,
int  advice 
)
related

Allocate an object of given size with an arena hint.

Parameters
heapOPHeap instance.
sizethe size of object.
advicehint to which arena slot to use.
Returns
pointer to the object allocated.

◆ OPCallocAdviced()

void * OPCallocAdviced ( OPHeap heap,
size_t  num,
size_t  size,
int  advice 
)
related

Allocate a chunk of memory filled with 0s with an arena hint.

Parameters
heapOPHeap instance.
numnumber of contiguous objects.
sizethe size of an object.
advicehint to which arena slot to use.
Returns
pointer to the memory allocated.

◆ OPDealloc()

void OPDealloc ( void *  addr)
related

Dealloc an object created by OPHeap.

Parameters
addrthe address of the object to be dealloc.

◆ ObtainOPHeap()

static OPHeap * ObtainOPHeap ( void *  addr)
related

Given any pointer in the OPHeap, returns the pointer to OPHeap.

Parameters
addrA pointer allocated by OPHeap.
Returns
pointer to OPHeap.

Definition at line 313 of file op_malloc.h.


The documentation for this struct was generated from the following file: