~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/memory/multi_malloc.cc

  • Committer: Monty Taylor
  • Date: 2009-09-30 07:01:32 UTC
  • mto: This revision was merged to the branch mainline in revision 1184.
  • Revision ID: mordred@inaugust.com-20090930070132-b1ol1xu1rpajdddy
Small namespace cleanup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 */
15
15
 
16
 
#include "mysys_priv.h"
 
16
#include "drizzled/global.h"
 
17
 
17
18
#include <stdarg.h>
18
 
 
 
19
#include <string.h>
 
20
#include <stdlib.h>
 
21
 
 
22
#include "drizzled/memory/multi_malloc.h"
 
23
 
 
24
namespace drizzled
 
25
{
 
26
namespace memory
 
27
{
19
28
/*
20
29
  Malloc many pointers at the same time
21
30
  Only ptr1 can be free'd, and doing this will free all
23
32
  memory area.
24
33
 
25
34
  SYNOPSIS
26
 
    my_multi_malloc()
27
 
      myFlags              Flags
 
35
    multi_malloc()
 
36
      zerofill             Whether or not to fill with 0
28
37
        ptr1, length1      Multiple arguments terminated by null ptr
29
38
        ptr2, length2      ...
30
39
        ...
31
40
        NULL
32
41
*/
33
42
 
34
 
void* my_multi_malloc(myf myFlags, ...)
 
43
void* multi_malloc(bool zerofill, ...)
35
44
{
36
45
  va_list args;
37
 
  char **ptr,*start,*res;
 
46
  void **ptr, *start;
 
47
  char *res;
38
48
  size_t tot_length,length;
39
49
 
40
 
  va_start(args,myFlags);
 
50
  va_start(args, zerofill);
41
51
  tot_length=0;
42
 
  while ((ptr=va_arg(args, char **)))
 
52
  while ((ptr=va_arg(args, void **)))
43
53
  {
44
 
    length=va_arg(args,uint);
 
54
    /*
 
55
     * This must be unsigned int, not size_t.
 
56
     * Otherwise, everything breaks.
 
57
     */
 
58
    length=va_arg(args, unsigned int);
45
59
    tot_length+=ALIGN_SIZE(length);
46
60
  }
47
61
  va_end(args);
48
62
 
49
 
  if (!(start=(char *) my_malloc(tot_length,myFlags)))
50
 
    return(0); /* purecov: inspected */
 
63
  if (!(start= malloc(tot_length)))
 
64
    return(0);
 
65
  if (zerofill)
 
66
    memset(start, 0, tot_length);
51
67
 
52
 
  va_start(args,myFlags);
53
 
  res=start;
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 **)))
55
71
  {
56
72
    *ptr=res;
57
73
    length=va_arg(args,uint);
58
 
    res+=ALIGN_SIZE(length);
 
74
    res+= ALIGN_SIZE(length);
59
75
  }
60
76
  va_end(args);
61
 
  return((void*) start);
 
77
  return start;
62
78
}
 
79
 
 
80
} /* namespace memory */
 
81
} /* namespace drizzled */