~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/src/kernel/vm/ndbd_malloc.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#include <ndb_global.h>
 
17
#include "ndbd_malloc.hpp"
 
18
#include <NdbMem.h>
 
19
 
 
20
//#define TRACE_MALLOC
 
21
#ifdef TRACE_MALLOC
 
22
#include <stdio.h>
 
23
#endif
 
24
 
 
25
#ifdef TRACE_MALLOC
 
26
static void xxx(size_t size, size_t *s_m, size_t *s_k, size_t *s_b)
 
27
{
 
28
  *s_m = size/1024/1024;
 
29
  *s_k = (size - *s_m*1024*1024)/1024;
 
30
  *s_b = size - *s_m*1024*1024-*s_k*1024;
 
31
}
 
32
#endif
 
33
 
 
34
static Uint64 g_allocated_memory;
 
35
void *ndbd_malloc(size_t size)
 
36
{
 
37
  void *p = NdbMem_Allocate(size);
 
38
  if (p)
 
39
  {
 
40
    g_allocated_memory += size;
 
41
#ifdef TRACE_MALLOC
 
42
    {
 
43
      size_t s_m, s_k, s_b;
 
44
      xxx(size, &s_m, &s_k, &s_b);
 
45
      fprintf(stderr, "%p malloc(%um %uk %ub)", p, s_m, s_k, s_b);
 
46
      xxx(g_allocated_memory, &s_m, &s_k, &s_b);
 
47
      fprintf(stderr, "\t\ttotal(%um %uk %ub)\n", s_m, s_k, s_b);
 
48
    }
 
49
#endif
 
50
  }
 
51
  return p;
 
52
}
 
53
 
 
54
void ndbd_free(void *p, size_t size)
 
55
{
 
56
  NdbMem_Free(p);
 
57
  if (p)
 
58
  {
 
59
    g_allocated_memory -= size;
 
60
#ifdef TRACE_MALLOC
 
61
    fprintf(stderr, "%p free(%d)\n", p, size);
 
62
#endif
 
63
  }
 
64
}