13
13
along with this program; if not, write to the Free Software
14
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#include "mysys_priv.h"
16
#include "drizzled/global.h"
17
18
#include <stdarg.h>
22
#include "drizzled/memory/multi_malloc.h"
20
29
Malloc many pointers at the same time
21
30
Only ptr1 can be free'd, and doing this will free all
36
zerofill Whether or not to fill with 0
28
37
ptr1, length1 Multiple arguments terminated by null ptr
34
void* my_multi_malloc(myf myFlags, ...)
43
void* multi_malloc(bool zerofill, ...)
37
char **ptr,*start,*res;
38
48
size_t tot_length,length;
40
va_start(args,myFlags);
50
va_start(args, zerofill);
42
while ((ptr=va_arg(args, char **)))
52
while ((ptr=va_arg(args, void **)))
44
length=va_arg(args,uint);
55
* This must be unsigned int, not size_t.
56
* Otherwise, everything breaks.
58
length=va_arg(args, unsigned int);
45
59
tot_length+=ALIGN_SIZE(length);
49
if (!(start=(char *) my_malloc(tot_length,myFlags)))
50
return(0); /* purecov: inspected */
63
if (!(start= malloc(tot_length)))
66
memset(start, 0, tot_length);
52
va_start(args,myFlags);
54
while ((ptr=va_arg(args, char **)))
68
va_start(args, zerofill);
69
res=reinterpret_cast<char *>(start);
70
while ((ptr=va_arg(args, void **)))
57
73
length=va_arg(args,uint);
58
res+=ALIGN_SIZE(length);
74
res+= ALIGN_SIZE(length);
61
return((void*) start);
80
} /* namespace memory */
81
} /* namespace drizzled */