00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <config.h>
00017
00018 #include <stdarg.h>
00019 #include <string.h>
00020 #include <stdlib.h>
00021
00022 #include <drizzled/memory/multi_malloc.h>
00023 #include <drizzled/definitions.h>
00024
00025 namespace drizzled
00026 {
00027 namespace memory
00028 {
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 void* multi_malloc(bool zerofill, ...)
00045 {
00046 va_list args;
00047 void **ptr, *start;
00048 char *res;
00049 size_t tot_length,length;
00050
00051 va_start(args, zerofill);
00052 tot_length=0;
00053 while ((ptr=va_arg(args, void **)))
00054 {
00055
00056
00057
00058
00059 length=va_arg(args, unsigned int);
00060 tot_length+=ALIGN_SIZE(length);
00061 }
00062 va_end(args);
00063
00064 #ifdef HAVE_VALGRIND
00065 if (!(start= calloc(0, tot_length)))
00066 return(0);
00067 #else
00068 if (!(start= malloc(tot_length)))
00069 return(0);
00070 if (zerofill)
00071 memset(start, 0, tot_length);
00072 #endif
00073
00074 va_start(args, zerofill);
00075 res= static_cast<char *>(start);
00076 while ((ptr=va_arg(args, void **)))
00077 {
00078 *ptr=res;
00079 length=va_arg(args,unsigned int);
00080 res+= ALIGN_SIZE(length);
00081 }
00082 va_end(args);
00083 return start;
00084 }
00085
00086 }
00087 }