36 #include "opic/common/op_macros.h" 48 #define OPHEAP_BITS 36 54 #define OPHEAP_SIZE (1UL << OPHEAP_BITS) 143 #define OPLENREF_MAX_LEN (1ULL << (64 - OPHEAP_BITS)) 257 __attribute__ ((malloc));
269 __attribute__ ((malloc));
281 __attribute__ ((malloc));
294 __attribute__ ((malloc));
407 uintptr_t uintref = (uintptr_t)ref;
408 if (OPLenRefIsEmpty(*ref) || OPLenRefIsDeleted(*ref))
432 uintptr_t uintref = (uintptr_t)ref;
433 if (OPLenRefIsEmpty(*ref) || OPLenRefIsDeleted(*ref))
436 return OPRef2Ptr(heap, OPLenRef2Ref(*ref));
462 size_t container_size)
464 uintptr_t uintref = (uintptr_t)ref;
470 if (data_size > container_size)
479 memcpy(ptr, data, data_size);
484 memcpy((
void*)(uintref +
sizeof(
oplenref_t)), data, data_size);
504 if (OPLenRefIsEmpty(*ref) || OPLenRefIsDeleted(*ref))
528 size_t container_size)
530 if (OPLenRefIsEmpty(*ref) || OPLenRefIsDeleted(*ref))
void * OPCalloc(OPHeap *heap, size_t num, size_t size) __attribute__((malloc))
Allocate a chunk of memory filled with 0s.
void * OPHeapRestorePtr(OPHeap *heap, int pos)
Restore a pointer from specified root pointer slot.
OPHeap * OPHeapOpen(const char *path, int flags)
OPHeap constructor which opens a memory mapped file to hold the heap.
Memory allocator object with persistent storage on disk.
uintptr_t oplenref_t
Another "pointer type" used within objects created in OPHeap.
#define OPHEAP_SIZE
Size of OPHeap.
void OPHeapClose(OPHeap *heap)
Flushes the changes in OPHeap to disk, closes the file, and un-maps the memory.
static opref_t OPPtr2Ref(void *addr)
Converts a pointer allocated in OPHeap to an opref_t.
static OPHeap * ObtainOPHeap(void *addr)
Given any pointer in the OPHeap, returns the pointer to OPHeap.
void OPDealloc(void *addr)
Dealloc an object created by OPHeap.
void OPHeapStorePtr(OPHeap *heap, void *ptr, int pos)
Store a pointer to a root pointer slot in OPHeap.
#define OPHEAP_BITS
Size of OPHeap represented in bits.
static void * OPLenRef2Ptr(oplenref_t *ref, size_t container_size)
Converts an oplenref_t reference to a regular pointer.
void * OPMalloc(OPHeap *heap, size_t size) __attribute__((malloc))
Allocate an object from OPHeap with given size.
uintptr_t opref_t
The "pointer type" used within objects created by OPHeap.
OPHeap * OPHeapOpenTmp()
OPHeap constructor which uses a temporal file to hold the heap.
static void * OPRef2Ptr(void *ptr_in_heap, opref_t ref)
Converts an opref_t reference to a regular pointer.
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.
void OPHeapMSync(OPHeap *heap)
Flushes changes in OPHeap to the file that holds the heap.
void * OPMallocAdviced(OPHeap *heap, size_t size, int advice) __attribute__((malloc))
Allocate an object of given size with an arena hint.
static void * OPLenRef2PtrOnHeap(oplenref_t *ref, size_t container_size, OPHeap *heap)
Converts an oplenref_t reference to a regular pointer on specified heap.
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.
#define OPLENREF_MAX_LEN
Maximum size oplenref_t can hold.
static void OPLenRefRelpace(oplenref_t *ref, void *data, size_t data_size, size_t container_size)
Relace the data stored in oplenref_t.
static void OPLenRefDelete(oplenref_t *ref, size_t container_size)
A destructor for oplenref_t.
static size_t OPLenRef2Size(oplenref_t ref)
Obtain the size encoded in oplenref_t.