00001 /* _________________________________________________________________________ 00002 * 00003 * MTGL: The MultiThreaded Graph Library 00004 * Copyright (c) 2008 Sandia Corporation. 00005 * This software is distributed under the BSD License. 00006 * Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00007 * the U.S. Government retains certain rights in this software. 00008 * For more information, see the README file in the top MTGL directory. 00009 * _________________________________________________________________________ 00010 */ 00011 00012 /****************************************************************************/ 00013 /*! \file qalloc.h 00014 00015 \author Jon Berry (jberry@sandia.gov) 00016 00017 \date 12/4/2007 00018 */ 00019 /****************************************************************************/ 00020 00021 #ifndef MTGL_QALLOC_H 00022 #define MTGL_QALLOC_H 00023 00024 #define _FILE_OFFSET_BITS 64 00025 00026 #include <sys/types.h> 00027 #include <unistd.h> 00028 00029 #ifdef __cplusplus 00030 extern "C" { 00031 #endif 00032 00033 struct mapinfo_s; 00034 struct dynmapinfo_s; 00035 00036 /* There are two kinds of maps: dynamic maps and static maps. Static maps have 00037 * very low overhead, but have the restriction that all allocations in them 00038 * have the same size (also, they're slower to create, initially). Dynamic maps 00039 * allow you to decide how much memory to use for each allocation at runtime, 00040 * but have more overhead both in terms of space and time (also, they're very 00041 * fast to create, initially). */ 00042 00043 /* The following functions are fairly straightforward. If the file specified 00044 * does not exist, it will be created. If the file specified does exist, it 00045 * will be loaded up. */ 00046 void* qalloc_makestatmap(const off_t filesize, void* addr, 00047 const char* filename, size_t itemsize, 00048 const size_t streams); 00049 void* qalloc_makedynmap(const off_t filesize, void* addr, 00050 const char* filename, const size_t streams); 00051 00052 /* This function is a special version of the previous two. It reads the map's 00053 * headers to determine it's vital details, and then loads it up as if you'd 00054 * used the appropriate function (between the previous two). */ 00055 void* qalloc_loadmap(const char* filename); 00056 00057 /* This function sync's the mmap'd regions to disk. */ 00058 void qalloc_checkpoint(); 00059 00060 /* This function performs a checkpoint, and then un-maps all of the currently 00061 * mapped regions */ 00062 void qalloc_cleanup(); 00063 00064 /* These are the allocation functions. 00065 * 00066 * The statmalloc() function allocates one chunk of the size of memory 00067 * associated with the specified static-size map. 00068 * The dynmalloc() function allocates one chunk of at least "size" bytes from 00069 * the specified dynamic-size map. 00070 * The malloc() function merges the previous two; if the specified map is a 00071 * static-size map, the size argument is ignored. 00072 */ 00073 void* qalloc_statmalloc(struct mapinfo_s* map); 00074 void* qalloc_dynmalloc(struct dynmapinfo_s* map, size_t size); 00075 void* qalloc_malloc(void* map, size_t size); 00076 00077 /* These are the deallocation functions. 00078 * 00079 * The statfree() function returns a static-size chunk to its map. 00080 * The dynfree() function returns a dynamic-size chunk to its map. 00081 * The free() function is a merging of the above two. 00082 */ 00083 void qalloc_statfree(void* block, struct mapinfo_s* map); 00084 void qalloc_dynfree(void* block, struct dynmapinfo_s* map); 00085 void qalloc_free(void* block, void* map); 00086 00087 #ifdef __cplusplus 00088 } 00089 #endif 00090 00091 #endif