OPIC
Object Persistence In C
|
Data Structures | |
struct | OPHeap |
Memory allocator object with persistent storage on disk. More... | |
Macros | |
#define | OPHEAP_BITS 36 |
Size of OPHeap represented in bits. | |
#define | OPHEAP_SIZE (1UL << OPHEAP_BITS) |
Size of OPHeap. | |
#define | OPLENREF_MAX_LEN (1ULL << (64 - OPHEAP_BITS)) |
Maximum size oplenref_t can hold. More... | |
Typedefs | |
typedef uintptr_t | opref_t |
The "pointer type" used within objects created by OPHeap. More... | |
typedef uintptr_t | oplenref_t |
Another "pointer type" used within objects created in OPHeap. More... | |
Functions | |
static opref_t | OPPtr2Ref (void *addr) |
Converts a pointer allocated in OPHeap to an opref_t. More... | |
static void * | OPRef2Ptr (void *ptr_in_heap, opref_t ref) |
Converts an opref_t reference to a regular pointer. More... | |
static size_t | OPLenRef2Size (oplenref_t ref) |
Obtain the size encoded in oplenref_t. More... | |
static void * | OPLenRef2Ptr (oplenref_t *ref, size_t container_size) |
Converts an oplenref_t reference to a regular pointer. More... | |
static void * | OPLenRef2PtrOnHeap (oplenref_t *ref, size_t container_size, OPHeap *heap) |
Converts an oplenref_t reference to a regular pointer on specified heap. More... | |
static void | OPLenRefCreate (oplenref_t *ref, void *data, size_t data_size, size_t container_size) |
A constructor for oplenref_t to hold the input data. More... | |
static void | OPLenRefDelete (oplenref_t *ref, size_t container_size) |
A destructor for oplenref_t. More... | |
static void | OPLenRefRelpace (oplenref_t *ref, void *data, size_t data_size, size_t container_size) |
Relace the data stored in oplenref_t. More... | |
#define OPLENREF_MAX_LEN (1ULL << (64 - OPHEAP_BITS)) |
#include <opic/op_malloc.h>
Maximum size oplenref_t can hold.
The size is roughly 256MB, which should be sufficient for most applications.
Definition at line 143 of file op_malloc.h.
#include <opic/op_malloc.h>
The "pointer type" used within objects created by OPHeap.
For all the objects relationship in OPHeap, user must use opref_t or oplenref_t instead of regular pointer. Regular pointers would be invalid when OPHeap is written to disk. To access the object referenced by opref_t, first dereference opref_t to regular pointer, then dereference the pointer.
Unfortunately, C type system is quite weak. It would be better if we have the following features:
Here is an example of how to reference other objects using opref_t:
Definition at line 109 of file op_malloc.h.
#include <opic/op_malloc.h>
Another "pointer type" used within objects created in OPHeap.
oplenref_t can encode an object created in OPHeap and the size of such object. User can query the size of the object by OPLenRef2Szie. The size of the object must smaller than OPLENREF_MAX_LEN, which is 256MB and suppose to be sufficient for regular use.
When oplenref_t is used in a container, oplenref_t can be used to encode the inline data in the container. The container holding oplenref_t can provide additional space next to oplenref_t to hold the inline data. When encoding or decoding oplenref_t the addtional space information must present so we know if the data is next to oplenref_t, or it is somewhere else in OPHeap.
Definition at line 135 of file op_malloc.h.
|
inlinestatic |
#include <opic/op_malloc.h>
Converts a pointer allocated in OPHeap to an opref_t.
addr | Any pointer that is allocated with OPHeap. |
Definition at line 326 of file op_malloc.h.
|
inlinestatic |
#include <opic/op_malloc.h>
Converts an opref_t reference to a regular pointer.
ptr_in_heap | Any pointer in the heap, including OPHeap*. |
ref | A opref_t value. |
Definition at line 340 of file op_malloc.h.
|
inlinestatic |
#include <opic/op_malloc.h>
Obtain the size encoded in oplenref_t.
ref | A oplenref_t value. |
Definition at line 353 of file op_malloc.h.
|
inlinestatic |
#include <opic/op_malloc.h>
Converts an oplenref_t reference to a regular pointer.
ref | Pointer to oplenref_t. |
container_size | Size of the container that holds oplenref_t. If used without a container, set this parameter to 0. |
Definition at line 405 of file op_malloc.h.
|
inlinestatic |
#include <opic/op_malloc.h>
Converts an oplenref_t reference to a regular pointer on specified heap.
This method is useful when oplenref_t is not on OPHeap, therefore we need to assist with a specific heap.
ref | Pointer to oplenref_t. |
container_size | Size of the container that holds oplenref_t. If used without a container, set this parameter to 0. |
heap | Address to OPHeap where the data pointer may locate at. |
Definition at line 430 of file op_malloc.h.
|
inlinestatic |
#include <opic/op_malloc.h>
A constructor for oplenref_t to hold the input data.
When oplenref_t used in a container, there would be some spaces next to the oplenref_t address that can hold inline data. The inline space is specified by the container_size. Data get copied to the inline space if the data_size is smaller than the container_size; otherwise the data would get copied to a newly allocated object in OPHeap. In either case, oplenref_t would store the information of which scheme was used.
ref | Pointer to oplenref_t. |
data | The data to copy over to OPHeap. |
data_size | Size of the data. This size must smaller than OPLENREF_MAX_LEN. |
container_size | Size of the container that holds oplenref_t. If used without a container, set this paramter to 0. |
Definition at line 461 of file op_malloc.h.
|
inlinestatic |
#include <opic/op_malloc.h>
A destructor for oplenref_t.
Deallocates the data stored in oplenref_t.
ref | Pointer to oplenref_t. |
container_size | Size of the container that holds oplenref_t. If used without a container, set this paramter to 0. |
Definition at line 502 of file op_malloc.h.
|
inlinestatic |
#include <opic/op_malloc.h>
Relace the data stored in oplenref_t.
Will deallocate the original data stored in oplenref_t if it exists.
ref | Pointer to oplenref_t. |
data | The data to copy over to OPHeap. |
data_size | Size of the data. |
container_size | Size of the container that holds oplenref_t. If used without a container, set this paramter to 0. |
Definition at line 527 of file op_malloc.h.