~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mulalloc.c

  • Committer: Brian Aker
  • Date: 2008-08-16 15:41:14 UTC
  • mto: This revision was merged to the branch mainline in revision 346.
  • Revision ID: brian@tangent.org-20080816154114-eufmwf31p6ie1nd6
Cleaned up depend in Proto utils. Modified int to bool. Put TmpTable class
into play.

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