Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00034 #include <stdio.h>
00035 #include <stdlib.h>
00036 #include "../config.h"
00037 #include "../dprint.h"
00038 #include "../globals.h"
00039 #include "mem.h"
00040
00041 #ifdef PKG_MALLOC
00042 #include "q_malloc.h"
00043 #endif
00044
00045 #ifdef SHM_MEM
00046 #include "shm_mem.h"
00047 #endif
00048
00049 #ifdef PKG_MALLOC
00050 #ifndef DL_MALLOC
00051 char* mem_pool = 0;
00052 #endif
00053
00054 #ifdef F_MALLOC
00055 struct fm_block* mem_block = 0;
00056 #elif defined DL_MALLOC
00057
00058 #else
00059 struct qm_block* mem_block = 0;
00060 #endif
00061 #endif
00062
00063
00068 int init_pkg_mallocs(void)
00069 {
00070 #ifdef PKG_MALLOC
00071
00072 #ifndef DL_MALLOC
00073 if (pkg_mem_size == 0)
00074 pkg_mem_size = PKG_MEM_POOL_SIZE;
00075 mem_pool = malloc(pkg_mem_size);
00076 #endif
00077 #ifdef F_MALLOC
00078 if (mem_pool)
00079 mem_block=fm_malloc_init(mem_pool, pkg_mem_size);
00080 #elif DL_MALLOC
00081
00082 #else
00083 if (mem_pool)
00084 mem_block=qm_malloc_init(mem_pool, pkg_mem_size);
00085 #endif
00086 #ifndef DL_MALLOC
00087 if (mem_block==0){
00088 LOG(L_CRIT, "could not initialize memory pool\n");
00089 fprintf(stderr, "Too much pkg memory demanded: %ld bytes\n",
00090 pkg_mem_size);
00091 return -1;
00092 }
00093 #endif
00094 #endif
00095 return 0;
00096 }
00097
00098
00099
00103 void destroy_pkg_mallocs(void)
00104 {
00105 #ifdef PKG_MALLOC
00106 #ifndef DL_MALLOC
00107 if (mem_pool) {
00108 free(mem_pool);
00109 mem_pool = 0;
00110 }
00111 #endif
00112 #endif
00113 }
00114
00115
00121 int init_shm_mallocs(int force_alloc)
00122 {
00123 #ifdef SHM_MEM
00124 if (shm_mem_init(force_alloc)<0) {
00125 LOG(L_CRIT, "could not initialize shared memory pool, exiting...\n");
00126 fprintf(stderr, "Too much shared memory demanded: %ld\n",
00127 shm_mem_size );
00128 return -1;
00129 }
00130 #endif
00131 return 0;
00132 }