00001 #ifndef QALLOC_H 00002 #define QALLOC_H 00003 00004 #define _FILE_OFFSET_BITS 64 00005 00006 #include <sys/types.h> 00007 #include <unistd.h> 00008 00009 #ifdef __cplusplus 00010 extern "C" { 00011 #endif 00012 00013 typedef struct mapinfo_s mapinfo_t; 00014 typedef struct dynmapinfo_s dynmapinfo_t; 00015 00016 /* there are two kinds of maps: dynamic maps and static maps. Static maps have 00017 * very low overhead, but have the restriction that all allocations in them 00018 * have the same size (also, they're slower to create, initially). Dynamic maps 00019 * allow you to decide how much memory to use for each allocation at runtime, 00020 * but have more overhead both in terms of space and time (also, they're very 00021 * fast to create, initially). */ 00022 00023 /* The following functions are fairly straightforward. If the file specified 00024 * does not exist, it will be created. If the file specified does exist, it 00025 * will be loaded up. */ 00026 void *qalloc_makestatmap(const off_t filesize, void *addr, 00027 const char *filename, size_t itemsize, 00028 const size_t streams); 00029 void *qalloc_makedynmap(const off_t filesize, void *addr, 00030 const char *filename, const size_t streams); 00031 00032 /* This function is a special version of the previous two. It reads the map's 00033 * headers to determine it's vital details, and then loads it up as if you'd 00034 * used the appropriate function (between the previous two). */ 00035 void *qalloc_loadmap(const char *filename); 00036 00037 /* This function sync's the mmap'd regions to disk. */ 00038 void qalloc_checkpoint(void); 00039 00040 /* This function performs a checkpoint, and then un-maps all of the currently 00041 * mapped regions */ 00042 void qalloc_cleanup(void); 00043 00044 /* These are the allocation functions. 00045 * 00046 * The statmalloc() function allocates one chunk of the size of memory associated with the 00047 * specified static-size map. 00048 * The dynmalloc() function allocates one chunk of at least "size" bytes from 00049 * the specified dynamic-size map. 00050 * The malloc() function merges the previous two; if the specified map is a 00051 * static-size map, the size argument is ignored. 00052 */ 00053 void *qalloc_statmalloc(mapinfo_t *map); 00054 void *qalloc_dynmalloc(dynmapinfo_t *map, size_t size); 00055 void *qalloc_malloc(void *map, size_t size); 00056 00057 /* These are the deallocation functions. 00058 * 00059 * The statfree() function returns a static-size chunk to its map. 00060 * The dynfree() function returns a dynamic-size chunk to its map. 00061 * The free() function is a merging of the above two. 00062 */ 00063 void qalloc_statfree(void *block, mapinfo_t *map); 00064 void qalloc_dynfree(void *block, dynmapinfo_t *map); 00065 void qalloc_free(void *block, void *map); 00066 00067 #ifdef __cplusplus 00068 } 00069 #endif 00070 00071 #endif